GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Regular Expression help PREG_REPLACE() (https://gfy.com/showthread.php?t=406094)

Veiga 12-21-2004 06:04 AM

Regular Expression help PREG_REPLACE()
 
Hello

I need to do a fast replace using preg_replace on php.

The syntax is:

Everything inside a html href tag "&" with a "#"

So, the html code:

<a href="https://gfy.com/link/blah&g">link &</a>
would go to
<a href="https://gfy.com/link/blah#g">link &</a>

Only replacing the & inside html.
thank you

Tim Tighty 12-21-2004 06:19 AM

PHP Code:

<?php
$strtoreplace 
"here is a link <href=test.php?id=1&1234=2345>terst</a>;"
$search "&";
$replace "#";
$text preg_replace($search$replace$strtoreplace);
echo 
$text ;
?>


Tim Tighty 12-21-2004 06:20 AM

should do the job allright

kaktusan 12-21-2004 06:23 AM

preg_replace("\&","#","<a href=\"https://gfy.com/link/blah&g\">link &</a>");

This should work man. Try it out ;)

Veiga 12-21-2004 09:17 AM

Yes, but I do NOT want to replace anything else than what's inside the href.


All times are GMT -7. The time now is 04:54 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123