473,769 Members | 3,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('"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>
---

Nov 21 '08 #1
0 1535

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

Similar topics

1
7635
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 " " (whitespace). I've prepared a line with preg_preplace function but it seem doesn't work. By the way: $oggetto = preg_replace("(\0-\037)|(\0177-\0377)", "\040", $_POST);
5
2071
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 expression...i thinked that something like "/\\+$/" is enough but i was wrong. I made some tries and finaly i removed "\" chars it with "/\\\+$/". It works (i'm proud with myself :)), but i can't understand why \\\ matchs single \, and \\ not...
11
1724
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 normal practise, I was working on the basis of leaving in all characters that I considered safe and stripping out everything else. This led me to think of what characters are actually safe, given that the user will want to be able to use at least basic...
14
24121
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 convert n = "" # init new string for i in str: if i in chr: # if special character in str n+='\\' # append it with a backslash n+=i
1
3168
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. I am quite new to xml and I am not sure how to deal with this situation. Is there a way to parse the jap characters ? or should the japanese characters be escaped in the xml file (i.e. Ӓ) for this to work.
4
1280
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 the fact that most functions I expect to use a string with, expect a char, or char array... Specifically, I am now looking at the String.Split function that has to be called as
1
1319
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 xmlDocument.Append("<description>"); xmlDocument.Append(SecurityElement.Escape(productDescription)); xmlDocument.Append("</description>"); The xml string I generate does validate as a valid rss feed at
12
1859
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 any match. My current approach is to look for matches in substrings with the escaped characters as boundaries between the substrings. However, then ^ and $ in the patterns are treated wrongly. (Although I use startpos and endpos parameters for...
1
2772
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 the solution requires fiddling with the machines registry. I cannot change registry of the server b/c I am not admin and I don't think I can have it changed at all regardless. Is there a way to get around this w/o changing registry? I've been...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.