• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP string replace with wildcards

crj

New Member
hi, i want to be able to change this:
Code:
<a href="whatever">link title</a>

into this:
Code:
<a href="whatever">link title</a>

basically, i want php to search for the string &lt;a href=&quot; and replace that with <a href=" but keep everything between the quotes the same and change &quot;&gt; into "> and the same for the link title and the </a>

i tried looking at eregi_replace but some the syntax looked really complex and i didn't know what was going on... can anybody help me figure it out

thanks
 
PHP:
<?php

function unhtmlentities($string) {
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}

?>

use this like so:
PHP:
<?php

$string = '&lt;a href=&quot;whatever&quot;&gt;link title&lt;/a&gt;';

// output: <a href="whatever">link title</a>
echo unhtmlentities($string);

?>
 
I actually sent the string through htmlspecialchars to eliminate html tags but i want to be able to allow <a href tags to go through but nothing else, that code looks like it would change everything back
 
crj said:
hi, i want to be able to change this:
Code:
&lt;a href=&quot;whatever&quot;&gt;link title&lt;/a&gt;

into this:
Code:
<a href="whatever">link title</a>

it does that.
 
Back
Top