str_replace construct
str_replace construct
(OP)
Hi,
$homepage = file_get_contents("http://www.imakenews.com/eletra/mod_archive_view.c...");
echo $homepage;
in $homepage there is a image source statement I'm trying to replace with nothing "" and then display the page without the image.
the statement is:
<img SRC="http://www.imakenews.com/bargainbooknews/bargainbo..." BORDER="0" alt="Bargain, Overstock, and Remainder Book News" hspace="6" vspace="1" align="top" >
I'm using the str_replace function but am having absolutely zero success. I've tried every way to present this string into the function for replacement. I already have it working in asp.net (VB) but need to get it working in PHP. I've tried double double quoting, single quotes, apostrophes etc..
Any help would be greatly appreciated. :)
Thanks
$homepage = file_get_contents("http://www.imakenews.com/eletra/mod_archive_view.c...");
echo $homepage;
in $homepage there is a image source statement I'm trying to replace with nothing "" and then display the page without the image.
the statement is:
<img SRC="http://www.imakenews.com/bargainbooknews/bargainbo..." BORDER="0" alt="Bargain, Overstock, and Remainder Book News" hspace="6" vspace="1" align="top" >
I'm using the str_replace function but am having absolutely zero success. I've tried every way to present this string into the function for replacement. I already have it working in asp.net (VB) but need to get it working in PHP. I've tried double double quoting, single quotes, apostrophes etc..
Any help would be greatly appreciated. :)
Thanks
RE: str_replace construct
If too many quotes in a string literal become confusing, try nowdoc.
Feherke.
feherke.ga
RE: str_replace construct
CODE
if you're doing anything else more detailed then you might consider phpQuery which can traverse the DOM tree and allow you to change attributes on the fly.
RE: str_replace construct
Justin, was your answer cut/truncated in some way ? $find is just initialized but not used. And generally I can not get its goal the way it currently is.
Feherke.
feherke.ga
RE: str_replace construct
where is that edit functionality we've all been asking for for ten years ....
RE: str_replace construct
Ok, then. Just got confused by the unnecessary escaping of colon ( : ) and double quote ( " ). They gave me the feeling that something else is missing.
Feherke.
feherke.ga
RE: str_replace construct
agreed that unnecessary for php.
RE: str_replace construct
You've presumed correctly. :) I'm a dot net developer. Been using basic since Bill Gates put it out on his MS DOS disc's.
Well a few days ago I had this project politely dropped on my desk :).
It is a wordpress site which I've never used before and of some PHP is needed. I once tried out PHP when it first came out but
opted to stay with VB. So to say the least I'm having fun, not :).
When I saw this " [^"]*? " or you pipes | I went out searching the PHP documentation for it. Still looking.
Thanks again for your response. It works just fine.
RE: str_replace construct
Just to give you an extra keyword for your searches, the "p" in preg_replace() stands for PCRE ( Perl-Compatible Regular Expressions ), a regular expression flavor.
Feherke.
feherke.ga
RE: str_replace construct
the square brackets denote a character class. i.e. any character in the square brackets, rather than all characters sequentially. the caret to start with negates the class. so NO characters in the square brackets...
the asterisk means 1 or more repetitions and the question mark makes the search 'un-greedy'. i.e. it stops the first time the next character is reached.
this is pretty standard posix compliant regular expressions. similar syntax exists in VB.
RE: str_replace construct
Thank you for the detailed explanation. I've never had to do much string manipulation.
Mainly basic searches and at the DB level.
I've went to the web and found a great page for posix compliant regular expressions.
I've also went and read up on the preg_replace function. 1st time seeing it. Nice function.
Thank again !
RE: str_replace construct