I am pretty new to PHP and am stuck on - what I think - is a generic
string handling problem.
I need to read and manipulate some HTML files and have a problem in
getting some substrings found even when - it is clear - strings are
there. (see a HTML chunk I need to edit at the end of this email).
In particular, the following functions are "randomly" working for me:
1) str_replace:
$chunk = str_replace('<!-- /templates/patternFinder/freePattern.txt --
><form method="post" ','',$chunk); ==it works (it finds and removethe string)
$chunk = str_replace('"2 0"><!-- /templates/patternFinder/
freePattern.txt --><form method="post" ','',$chunk); ==it doesnt
work (does not find and remove the substring)
2) preg_match_all:
$pattern = '~<h6>(.*?)</h6><img src=(.*?) ~si';
if (preg_match_all ($pattern, $chunk, $matches)>0) { ...
==it works
$pattern = '~<h6>(.*?)</h6><img src="(.*?)" ~si';
if (preg_match_all ($pattern, $chunk, $matches)>0) { ...
==it doesnt work (it does not return any match)
I believed this has to do with the chars to be escaped but I have
still not found/understood what chars need to be escaped or not.
I have also tried the addcslashes function, changing from single to
double quotes string delimiters without success.
I use PHP 5.2.3(?) with IIS locally.
I really appreciate any help or reply and can provide more
information, if needed.
Thanks a lot.
Cheers,
Stef
HTML file chunk
---
<table width="100%"><t body><tr><td colspan="3" valign="top"
align="left"><h 6>Roll-Down Wristers</h6><img src="http://
www.lionbrand.c om/stores/lionbrand/thumbs/81000ada.jpg" alt="Image of
Roll-Down Wristers" width="150" border="0"><br> </td><td></td><td
valign="top" align="right" height="20"><ta ble width="400" border="0"
cellspacing="0" ><tbody><tr>< td valign="top" align="right"
height="20"><!-- /templates/patternFinder/freePattern.txt --><form
method="post" name="kitform19 22242962" action="http://
www.lionbrand.c om/cgi-bin/patternBuyer.cg i"><input name="qty"
value="1" type="hidden">< input name="itemKey" value="19222429 62"
type="hidden">< input name="store" value="/stores/eyarn"
type="hidden">< input name="kit" value="1" type="hidden">< input
name="transNum" id="tn192224296 2" value="" type="hidden">< input
name="sourceIte m" value="" type="hidden">< input name="su"
id="su192224296 2" value="" type="hidden">< table style="border-color:
rgb(217, 203, 194); border-collapse: collapse;"
border="1"><tbo dy><tr><td class="B1" id="b1192224296 2"
onmouseover="bg On('b1192224296 2','T3b');" onmouseout="bgO ff
('b11922242962' );" width="100"><a class="B1a" href="http://
www.lionbrand.c om/patterns/81000AD.html?no Images=">Free Pattern</a></
td><td class="B1" id="b2192224296 2" onmouseover="bg On
('b21922242962' ,'T3b');" onmouseout="bgO ff('b2192224296 2');"
width="100"><a class="B1a" href="javascrip t:
document.kitfor m1922242962.sub mit();">Buy Materials</a></td></tr></
tbody>
---