PDA

View Full Version : [PHP] Preg_Replace



[Oli]
01-03-2008, 05:55 PM
$find = array(

'http:\/\/www\.'

);

$change = array(

''

);


I get this:



preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash



which char didn't I backslash or ??

I want http://www. to be replaced with nothing, empty space

Blob
01-03-2008, 06:07 PM
/http\:www\./i

That should work I think

[Oli]
01-03-2008, 06:10 PM
/http\:www\./i

That should work I think

Ooo right, crap i forgot the - i -

RYANNNNN
02-03-2008, 01:43 PM
I believe preg is only used for regular expressions, but since you only want to replace http://www you can use str_replace.

Navicat
08-03-2008, 04:12 AM
str_replace("http://www", "", $string);

Rockstar
08-03-2008, 04:59 PM
Its something like


mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit [, int &$count ]] )


Is int it :S

Sorry if this didn't help.

Navicat
08-03-2008, 05:16 PM
Good job, you copied from PHP.net?

He doesn't even need to use preg_replace, when he can just use str_replace

Protege
09-03-2008, 11:47 AM
This reminds me when I wanted to get the habbo image off habbo homes, But I didn't know they had a URL for it, and this is where I got screwed up


<?
$text = str_replace(chr(34), "", $store);
if (preg_match('/<div class=profile-figure>(.*?)<\/div>/is',$text,$found))
{
$image = $found[1];
?>That was for what I did, maybe you can learn from that and for also what your doing you don't need to use preg_match.


<?
$newurl = str_replace("http://www.", "", $url);
?>

Want to hide these adverts? Register an account for free!