Ereg_replace with double quotes
Hi, I do know a bit PHP and also had no probles with regular expressions, until now. This is my code:
$string = ereg_replace("([\"](.*)[\"])", "<span class=\"style10\">\\2</span>", $sting);
. Why doesn't it work? It all runs fine when using:
$string = ereg_replace("([*](.*)[*])", "<span class=\"style10\">\\2</span>", $sting);
, but I want PHP to recognize quotes. Please help :-/.
Related Article: Php Regular expression multiline problem
is a PHP discussion thread by DILO3D that has 1 reply, was last updated 1 year ago and has been tagged with the keywords: expression, multiline, php, problem, regular.
RoyalElite96
Light Poster
44 posts since Dec 2010
Reputation Points: 16
Solved Threads: 2
Skill Endorsements: 0
Isn't ereg_replace() deprecated now? Take a look into using preg_quote() instead.
Here's an example:
<?php
// In this example, preg_quote($word) is used to keep the
// asterisks from having special meaning to the regular
// expression.
$textbody = "This book is *very* difficult to find.";
$word = "*very*";
$textbody = preg_replace ("/" . preg_quote($word) . "/",
"<i>" . $word . "</i>",
$textbody);
?>
This should work the same with asterisks as it does for double quotes
nonshatter
Posting Whiz
377 posts since Nov 2009
Reputation Points: 39
Solved Threads: 64
Skill Endorsements: 0
Thanks you, but there are a few problems:
That way it only recognizes the word *very*, but any word written in asterisks or double quotes...
Also how can I keep it from recognizing double quotes in HTML tags.
:)
RoyalElite96
Light Poster
44 posts since Dec 2010
Reputation Points: 16
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 2 Years Ago by
nonshatter