0

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 :-/.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by RoyalElite96
1

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

Edited by nonshatter: n/a

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.

:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.