Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing variables in HTML with Perl like regex's

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello:

I am having a bit of trouble with a regular expression I am writing for PHP.

I am using the preg_replace() function so that I can use a nice Perl regular expression.

I want to search through a string that containts PHP variables that begin with a $ so I have constructed the following regular expression:

[tt]
$html = &quot;<html><head><title>$title</title></head><body>$user <br>$pass <br> this string has vars in it </body></html>&quot;;
$pattern = &quot;/(\$\D+.?\D)/&quot;;
$replace = &quot;/ /gi/&quot;;
preg_replace($pattern,$replace,$html);
[/tt]

I want to search through HTML and replace everything that begine with $ and has some characters after it, to be replaced with a space.

In Perl, I constructed the following regular expression and it works fine:

[tt]
$html = &quot;<html><head><title>$title</title></head><body>$user <br>$pass <br> this string has vars in it </body></html>&quot;;
$html =~ s/\$\b+.?\b/ /gi;
[/tt]

What is wrong with my PHP code?

Any help is appreciated.

Thank,

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Nevermind, I got it.

I got it working with the str_replace() function.

i.e.:

[tt]
$html = str_replace(&quot;\$title&quot;,&quot;this is the title&quot;,&quot;$html&quot;);
[/tt]

If anyone could help me solve the above problem getting the regular expression to work, I would be very appreciative.

Thanks,

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top