473,413 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 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.

Cheers,
Stef

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></
tbody>
---

Nov 21 '08 #1
0 1509

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Francesco | last post by:
I've created a form asking a user to enter a text; the user can press key or any other "strange" non printable char that i want to strip away from the entred text and replace it with a " "...
5
by: sbd! | last post by:
I had a problem with string which have some \ chars at the end of the string. For example: $String = "I want this **** out of here\\\\\\\\\"; I needed to remove it useing regular...
11
by: Derek Fountain | last post by:
I was just writing a sanitisation route for a bit of user input. The data is an English text description of a product, and will go into a DB, then back out to other user's browsers. As per...
14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
1
by: Sriv Chakravarthy | last post by:
I am trying to use xerces-c SAX parser to parse japanese characters. I have a <?xml... utf-8> line in the xml file. When the parser encounters the jap characters it throws a UTFDataFormatException....
4
by: Sky | last post by:
Hi. Coming from PHP where all things are strings, the char is a bit hard to get used to. So far, I'm not really sure what the dif/use is between a string and a char array...except notation, and...
1
by: John A Grandy | last post by:
I am using StringBuilder to build a string containing xml that is Response.Write() to the browser as an rss feed. To replace invalide xml chars, I am using code fragments such as ...
12
by: Torsten Bronger | last post by:
Hallöchen! I need some help with finding matches in a string that has some characters which are marked as escaped (in a separate list of indices). Escaped means that they must not be part of...
1
by: Durango2008 | last post by:
Hello, I am kind of in a bad situation. I am trying to read data out of Excel using OLEDB, however any data more than 255 characters gets truncated. I found out that this is a known issue and that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.