471,596 Members | 822 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

What chars to be escaped/not and when?

Hi all,

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 remove
the string)

$chunk = str_replace('"20"><!-- /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.


HTML file chunk
<table width="100%"><tbody><tr><td colspan="3" valign="top"
align="left"><h6>Roll-Down Wristers</h6><img src="http://
www.lionbrand.com/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"><table width="400" border="0"
cellspacing="0"><tbody><tr><td valign="top" align="right"
height="20"><!-- /templates/patternFinder/freePattern.txt --><form
method="post" name="kitform1922242962" action="http://
www.lionbrand.com/cgi-bin/patternBuyer.cgi"><input name="qty"
value="1" type="hidden"><input name="itemKey" value="1922242962"
type="hidden"><input name="store" value="/stores/eyarn"
type="hidden"><input name="kit" value="1" type="hidden"><input
name="transNum" id="tn1922242962" value="" type="hidden"><input
name="sourceItem" value="" type="hidden"><input name="su"
id="su1922242962" value="" type="hidden"><table style="border-color:
rgb(217, 203, 194); border-collapse: collapse;"
border="1"><tbody><tr><td class="B1" id="b11922242962"
onmouseover="bgOn('b11922242962','T3b');" onmouseout="bgOff
('b11922242962');" width="100"><a class="B1a" href="http://
www.lionbrand.com/patterns/81000AD.html?noImages=">Free Pattern</a></
td><td class="B1" id="b21922242962" onmouseover="bgOn
('b21922242962','T3b');" onmouseout="bgOff('b21922242962');"
width="100"><a class="B1a" href="javascript:
document.kitform1922242962.submit();">Buy Materials</a></td></tr></

Nov 21 '08 #1
0 1424

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Derek Fountain | last post: by
14 posts views Thread by tertius | last post: by
1 post views Thread by Sriv Chakravarthy | last post: by
4 posts views Thread by Sky | last post: by
12 posts views Thread by Torsten Bronger | last post: by
1 post views Thread by Durango2008 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.