Welcome Guest, Not a member yet? Register   Sign In
php preg_replace function
#21

[eluser]basty_dread[/eluser]
hi sophistry.. i just figured out a simple way..

Code:
$appendthis = "<a href='http://codeigniter.com'>"; // this is what  i supposed to append after replacing spaces with dash (-)
$string = "the quick brown brown fox jumps over the lazy dog, Brown Fox. <h2>The Brown Fox</h2>";
$save = preg_replace('/(<h.*>(.*)<\/h.*>)/ie',"str_replace(' ','-','QWER$1ASDF')" , $string);
$save = str_replace("QWER",$appendthis,$save); // start of link
$save = str_replace("ASDF","</a>",$save);
print_r($save);

and it worked.. huray!
#22

[eluser]sophistry[/eluser]
that's great you did it! one problem with that approach is that all the links will point to one place: codeigniter.com - seems like that fits your spec however, so well done.

cheers.




Theme © iAndrew 2016 - Forum software by © MyBB