troubleshooting Question

preg_replace - replace text contains "$0.32" and "dollar 0" is interpreted as the matching text!

Avatar of rivusglobal
rivusglobalFlag for Canada asked on
PHP
5 Comments1 Solution253 ViewsLast Modified:
Considering the following example, how can I get preg_replace to ignore the function of the replacement parameter that is introduced by the replacement text?

$text = "This item costs $0.99";
$html = "<b>%COST%</b>";

$html = preg_replace( "%COST%", $text, $html );

---------- the above produces the string below:

$html = "<b>This item costs %COST%.99</b>";

---------- but i want the previous code to produce this:

$html = "<b>This item costs $0.99</b>";

How can I do this?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros