473,396 Members | 1,766 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,396 software developers and data experts.

Any idea what's wrong with this code snippet?

<?

$pattern = "<script[^>]*?>.*?</script>";
$replacement = "";
$subject = " <Description><script
src='http://x.com/rd/j/rf.jsp?pD=41422'></script>Official site. Enjoy
lower rates in the heart of Montreal at the

Fairmont Queen Elizabeth. Save 10% if you book 3 weeks in advance. From
$199 CAD per night. Fairmont, Creating Memories.</Description>";

$test = preg_replace($pattern,$replacement,$subject);

echo $test;
?>

Generates:

Warning: preg_replace(): Unknown modifier ']' in
/web/sites/kerryc/buyers-source-online.com/testme.php on line 9

I just wanna replace the <script tag with nothing...it can't be THAT
hard :)

G-Man

Sep 26 '06 #1
2 1056
The first character of the pattern is considered the delimiter
character. Try something like:

$pattern = '#<\s*script\s+.*?>.*?<\s*/\s*script>#is';

The delimiter character (#) separates the regular expression from the
pattern modifiers.

You might be interested in PEAR::HTML_Safe, which sanitizes HTML.

Best Regards,

John Peters

GeoffreyF67 wrote:
<?

$pattern = "<script[^>]*?>.*?</script>";
$replacement = "";
$subject = " <Description><script
src='http://x.com/rd/j/rf.jsp?pD=41422'></script>Official site. Enjoy
lower rates in the heart of Montreal at the

Fairmont Queen Elizabeth. Save 10% if you book 3 weeks in advance. From
$199 CAD per night. Fairmont, Creating Memories.</Description>";

$test = preg_replace($pattern,$replacement,$subject);

echo $test;
?>

Generates:

Warning: preg_replace(): Unknown modifier ']' in
/web/sites/kerryc/buyers-source-online.com/testme.php on line 9

I just wanna replace the <script tag with nothing...it can't be THAT
hard :)

G-Man
Sep 26 '06 #2
Thanks! That's very helpful!

G-Man

Sep 26 '06 #3

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

Similar topics

3
by: jwayne | last post by:
I'm trying to implement a navigation bar with multiple a href classes. The following example works exactly as I want it to, but for Internet Explorer only. Firefox does not indent each link. ...
7
by: Vic | last post by:
Dear All, I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an...
9
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
28
by: federico_bertola | last post by:
Hi everybody! I have this function: int Scan(char String) { printf("%s", String); } it works but when I try to pass a dotted string o separetad with (" ", "_" , "-" ...ecc)
0
by: andy6 via DotNetMonster.com | last post by:
I want to display a webpage. The user selects a value from a drop down. This value is put into a custom header and added to the http pipeline. Then the page is redirected in the EndRequest method...
7
by: Jason Kid | last post by:
Hi, Please tell me what's wrong with the following code. private bool CheckIt( int iArg, bool fArg) { bool fIsGood = false;
1
by: crystalite | last post by:
hi all, I have a problem for logging in. I want user to log in into their system using company GUID and user GUID. But when the logon button is submitted, the GUIDs(which is captured in the...
1
by: frankatle | last post by:
Hi. I am writing a opensource code snippet manager in python (pyqt4). The idea is that users can upload their snippets to remote subversion server, (if they choose) and add comments to existing...
2
by: Zytan | last post by:
You can download them here: http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx This snippet seems wrong: Visual C# 2005 Code Snippets -filesystem -Search a Directory for Files Recursively ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.