Hi
I've been coding in PHP for a little while now and was starting to feel
pretty confident but then realise I need to understand regular expressions
to solve a particular problem I've got ... What a horrible can of worms
regex is!! (to the uninitiated at least).
I realise that if I spend the next few weeks researching regex I'll probably
find the answer but I was wondering if anyone here would kindly help speed
up the process?
Basically I am grabbing the html from another URL, finding a specific <a
href .. </a> block and replacing the contents of that block with another
link. (n.b. the code examples below are pseudo code - I realise I need to
'escape' some characters)
Here's how I'm grabbing the source html :
$html = join ("", file (http://www.sitexyz.com/index.htm));
the link I want to replace looks something like :
<a href="http://www.sitexyz.com/page2"><img height="120"
src="origpic.jpg"></a>
Note - the only thing I know to be constant about the above link is that the
height is always 120 - the link destination and source image are completely
unpredictable.
Here's a variable holding the replacement link to my site using a different
image :
$newlink = "<a href="http://www.mysite.com"><img height="120"
src="mypic.jpg"></a>";
So... how do I use preg_replace() or ereg_replace() to find the <a href ..
</a> block encompassing an image of height 120 and replace it with the
contents of my $newlink variable?
*** To precis my question ... How do I replace an HTML link (where all I
know is the image height) with a link of my own? ***
TIA!
p.s. I promise I'll go and sit on the top of a mountain and not come down
until I've memorised & understood everything about regex ... once I've
sorted this problem! :o)
--
Sorby