I've looked all over the place and cant seem to find how to do str_replace but search the whole document instead of just a string.
For example, by using string replace, I can check a string, look for certain text, and replace that text with something else.
I want to look in the whole page (The whole index.php page). Look for certain text, and replace that text with new text.
I can accomplish this with jquery, the only problem is that it is done after the page loads so its loading double the information. I need it done before the page loads. Or maybe there is another way to change the text with javascript before the page even loads. But figure PHP would be best for this. Any suggestions?
--UPDATE ONE--
I'm using the easyazon plugin to load in products from amazon. Here is the specific code that pull in the image from amazon into my index page.
<?php if($image_atts) { ?>
<div class="easyazon-block-image-container">
<?php printf('<a %s><img %s /></a>', easyazon_collapse_attributes($link_atts), easyazon_collapse_attributes($image_atts)); ?>
</div>
<?php } ?>
Under the $image_atts array, the code there is>
if(isset($item['images']) && is_array($item['images'])) {
$image_index = 3;
while($image_index >= 0) {
if(isset($item['images'][$image_index])) {
$image_atts = array(
'alt' => $item['title'] ? $item['title'] : '',
'class' => 'easyazon-block-information-image',
'height' => $item['images'][$image_index]['height'],
'src' => $item['images'][$image_index]['url'],
'width' => $item['images'][$image_index]['width'],
);
break;
}
$image_index--;
}
} else {
$image_atts = false;
}
When looking at the source of the index.php after its generated. The image tag looks something like this.
<div class="easyazon-block-image-container">
<img class="xxx" src="https://xxxx.amazon.com/xxxx/xxx/xxx/xxxxx120.jpg">
</div>
Here is where lies my issue. If you look at the src part of the image tag, it pulls a small image down from amazon at 120px width as shown by the end of the filename.
What I need is to pull down a larger width image from amazon by changing the 120 to a 300.
https://xxxx.amazon.com/xxxx/xxx/xxx/xxxxx300.jpg
Which in turn pulls down the image at 300px wide.
I tried doing this in jquery, to search for the string "120" and replace it with "300". This worked successfully but in turn becuase it happened after the browser loaded, it caused the browser the download 2 different images. One at 120px and one at 300px. So that is definitely a no go. For every image on the page it would download both versions of the image.
What i need to do is look for the string 120, in the easyazon-block-image-container, and then change it to 300, BEFORE it is sent to the browser. I hope this helped in giving a little more of the code.
I don't want to give to much code on the plugin for the developers privacy. But for my own defense, I looked all over the plugin and cant find anywhere where the plugin is telling itself to download the 120px version of the image. If that was the case I could have just changed it to 300 in the code. Any help would be appreciated. One of the last thing keeping me from going live with my site :(
A string can be as short or long as you want, str_replace()
should work fine.