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

Recommended Answers

All 2 Replies

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

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.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.