We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,201 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
2
Replies
2 Days
Discussion Span
2 Years Ago
Last Updated
3
Views
Question
Answered
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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0582 seconds using 2.65MB