I'm trying to use str_replace()
to search and replace specific strings in html pages. For example, I am replacing:
$search_string = 'The new funding follows a <a href="http://blog.classpass.com/2015/01/15/were-so-excited-to-share-our-biggest-news-ever/">$40 million raise announced</a> in January.';
with
$replacement = '<span class="newString">The new funding follows a <a href="http://blog.classpass.com/2015/01/15/were-so-excited-to-share-our-biggest-news-ever/">$40 million raise announced</a> in January.</span>';
$subject = file_get_contents("some-web-site.html");
$new_string = str_replace($search_string, $replacement, $subject);
However, the replacement doesn't work, when $subject
contains a lot of html. If i just do:
$subject = "some text some text " . $search_string . "some text some text";
the sentence is correctly replaced. The issue seems to arise specifically due to the
element.. if the $search_string
does not contain
then it will be replaced successfully no matter the complexity of the $subject
element (i.e. even if it contains a full web page).
Any idea why is that ?