У меня есть такая строка php:
$html = '<figure class="image article-image"><img alt="In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout." src="https://image.jpg" caption="true"><br /> <figcaption>In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout. To say "HES ON FIRE" would be an understatement.</figcaption><br /> </figure><br /> <p>This record is a tight one to say the least. Who doesn’t know about the over-the-top basketball antics of <em>NBA Jam</em>? Winning a game isn’t necessarily tough, but how much you can beat a computer controlled opponent by is a whole other story. <em>Jam</em> has some AI rubber banding mechanics that come into play to try to keep things fairn which a few opponent shots made it to their basket. All these things considered make this look like it’s going to be a record worth watching as Pudenz claims king of the hill, yet remains hungry for more.  </p><br /> <p><iframe width="100%" height="220" allowfullscreen="allowfullscreen" frameborder="0" src="https://view.vzaar.com/13686906/player" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen" allowtransparency="true" type="text/html" class="video-player" title="video player" name="vzvd-13686906" id="vzvd-13686906"></iframe></p><br /> <h2><strong><u>Arron Pitchford - <em>Game & Watch Gallery - Manhole</em> (Game Boy/Game Boy Color): Classic - Points</u></strong></h2><br /> <figure class="image article-image"><img alt="Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency." src="https://image1.jpg" caption="true"><br /> <figcaption>Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency.</figcaption><br /> </figure><br /> <p>Next we take a look at a handheld blast from the past. The <em>Game & Watch Gallery</em> was a fantastic collection of the grandfathers of all handheld gaming and <em>Manhole</em> is a great little look into the frantic nature of some of these games. p the task of bridging gaps in two structures for a d amassed an amazing 9,999 points, absolutely decimating the ssic-points/" target="_blank">previous record set on the leaderboard</a> back in 2017 (385 by s on how he could have gotten more points in his run, but with such a vast lead, he is content to sit at the top with what he’s got for the time being. Fair enough, as it will take patience and dedication to dethrone him.</p><br /> <p><iframe width="100%" height="220" allowfullscreen="allowfullscreen" frameborder="0" src="https://view.vzaar.com/13611958/player" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen" allowtransparency="true" type="text/html" class="video-player" title="video player" name="vzvd-13611958" id="vzvd-13611958"></iframe></p><br /> <h2><strong><u>Angela Stefanski - <em>Burnout Revenge</em> (Xbox 360 - NTSC): Crash - Drain Damage (Dollars)</u></strong></h2><br /> <figure class="image article-image"><img alt="You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal." src="image2.jpg" caption="true"><br /> <figcaption>You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal.</figcaption><br /> </figure><br /> <p><em>Burnout</em> is a series most certainly known for its arcade and over-the-top racing, but anyone who’s gotten comfy behind the wheel of these wild games know the destruction and chaos one can sow in them. In this <em>Burnout Revenge</em> record, destruction to extremes. The atch Stefanski’s glorious appetite for destruction in this one.</p><br /> <p><iframe width="100%" height="220" allowfullscreen="allowfullscreen" frameborder="0" src="https://view.vzaar.com/14078681/player" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen" allowtransparency="true" type="text/html" class="video-player" title="video player" name="vzvd-14078681" id="vzvd-14078681"></iframe></p><br /> <h2><strong><u>Adam Hulbert - <em>Wizards of Wor</em> (Commodore 64 - Emulator): Points</u></strong></h2><br /> <figure class="image article-image"><img alt="Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that." src="https://image3.jpg caption="true"><br /> <figcaption>Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that.</figcaption><br /> </figure><br /> <p>This one takes us back into the Commodore 64 days with a little emulated play. tic mazes of <em>Wizards of Wor</em> to blast some beasties r 20 minutes. It’s enough to outdo the last <em>up a record of 148,900 back in 2016. There’s a lot to consider for this run. The way the monsters move, your reflexes for killing them, and the monster that sets up double points for whole stages means players are going to need a little bit of luck and a lot of skill on their side if they want to challenge Hulbert’s high score.</p><br /> <p><iframe width="100%" height="220" allowfullscreen="allowfullscreen" frameborder="0" src="https://view.vzaar.com/13977536/player" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen" allowtransparency="true" type="text/html" class="video-player" title="video player" name="vzvd-13977536" id="vzvd-13977536"></iframe></p><br /> <h2><strong><u>Donald Hayes - <em>Centipede</em> (Arcade): Points (Tournament Settings)</u></strong></h2><br /> <figure class="image article-image"><img alt="A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen." src="https://image4.jpg" caption="true"><br /> <figcaption>A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen.</figcaption><br /> </figure><br /> <p>This is a record we had the pleasure of seeing in person for it’s massive entirety. Back at Score Wars at the end of March 2018 in Santa Fe, New Mexico, act=8&ved=2ahUKEwiY2Jr0w9jaAhUl0YMKHTrJB_wQFjAAegQ IABAo&url=/score-wars-pro-galaga-tourney-results-andrew-barrow-becomes-world-champ&usg=AOvVaw0qW2LgK-QRX_vCzVxl7Bey" target="_blank">fantastic <em>Galaga</em> play</a> wasn’t the only thing going on. Retro gaming pros were also making attempts at their own previously set records and achieving new heights. One of those pros was <em>Centipede</em> master dible marathon lasting nearly 10 hours, Hayes pursued his previous <em>et="_blank">Centipede high score</a></em> to set a new one and did when he finally blew his last life at an incredible 7,750,817 points. His previous record sat at 7,111,111 on the <em>gs Leaderboard</a></em>. We had a chance to talk to Hayes after the fact and ask him what it took to make a score like that. He kindly shared that much of the skill doesn’t just land in moving fast, but also knowing where to stop.</p><br /> <p>“The control over the stop-and-go of the ship with the trackball is something I feel like I can tell you about all day,” Hayes claimed. “But it’s also the sort of muscle memory and reflexes you can’t teach with words. It’s what lets me get records like these and be able to say I’m the best at this.” Bold, but fair words from the champ, and a record that will take dedication and practice of an incredible level to match. To see Hayes in action was a pleasure, and this is a record more than earned.</p><br /> </p>';
Когда я использовал это напрямую, я получил результат (замененная строка):
$changeimgoriarr = array('<img alt="In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout." src="https://image.jpg" caption="true">','<img alt="Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency." src="https://image1.jpg" caption="true">','<img alt="You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal." src="image2.jpg" caption="true">','<img alt="Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that." src="https://image3.jpg caption="true">','<img alt="A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen." src="https://image4.jpg" caption="true">');
$changeimgnewarr = array('<a href="https://image.jpg"><img alt="In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout." src="https://image.jpg" caption="true"></a>','<a href="https://image1.jpg"><img alt="Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency." src="https://image1.jpg" caption="true"></a>','<a href="image2.jpg"><img alt="You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal." src="image2.jpg" caption="true"></a>','<a href="https://image3.jpg><img alt="Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that." src="https://image3.jpg caption="true"></a>','<a href="https://image4.jpg"><img alt="A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen." src="https://image4.jpg" caption="true"></a>');
echo str_replace($changeimgoriarr, $changeimgnewarr, $html);
Код для получения значений src изображения из строки:
preg_match_all('/<img[^>]* src="https:\/\/[^>]*">/i', $html, $resultimg);
$changesimgs = $resultimg[0];
foreach ($changesimgs as $ckey => $cval) {
$changeimgori[] = "'" .$cval ."'";
preg_match('/"https:\/\/[^"]*"/i', $cval, $resultsrc);
$changeimgnew[] = "'". '<a href=' . $resultsrc[0] . '>' . $cval . '</a>' ."'";
}
$changeimgnewarr = implode(',', $changeimgnew);
$changeimgoriarr = implode(',', $changeimgori);
Я получил два массива $ changeimgoriarr & $ changeimgnewarr
$ changeimgoriarr =Исходные значения массива, которые я получил из текущей строки $ html;
$ changeimgnewarr = Строка, которая будет изменена и создана из приведенного выше кода.
Я проверил значения обоих массивов Iполучил от функции implode:
$changeimgoriarr = '<img alt="In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout." src="https://image.jpg" caption="true">','<img alt="Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency." src="https://image1.jpg" caption="true">','<img alt="You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal." src="image2.jpg" caption="true">','<img alt="Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that." src="https://image3.jpg caption="true">','<img alt="A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen." src="https://image4.jpg" caption="true">';
$changeimgnewarr = '<a href="https://image.jpg"><img alt="In Lebron-less era of the NBA, Pudenz makes the Miami Heat look like the Jordan-Era Chicago Bulls in this stunning and proficient blowout." src="https://image.jpg" caption="true"></a>','<a href="https://image1.jpg"><img alt="Pitchford takes the pains to make sure hundreds of little guys get safely to where they want to go, managing their frenzied and hectic moves across the bridges with incredible balance and efficiency." src="https://image1.jpg" caption="true"></a>','<a href="image2.jpg"><img alt="You think you know a good crash in Burnout? Stefanski puts on an explosive spectacle that makes this record a vehicular maelstrom of twisted metal." src="image2.jpg" caption="true"></a>','<a href="https://image3.jpg><img alt="Wizords of Wor has a ton of elements to manage if you want to lay claim to the title of Worlord Supreme. Hulbert handles the mess of monsters well to do just that." src="https://image3.jpg caption="true"></a>','<a href="https://image4.jpg"><img alt="A video almost doesnt do it justice. Donald Hayes cold concentration and reflexes are a sight to be seen." src="https://image4.jpg" caption="true"></a>';
Но при использовании замены строки после того, как она основана на не работающем массиве implode:
echo str_replace(array($changeimgoriarr), ($changeimgnewarr), $html);
Скажите, пожалуйста, в чем проблема, почемуне работает после взорванных массивов.