Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    2,492
    Tokens
    147

    Latest Awards:

    Default [PHP] Preg_Replace

    PHP Code:
            $find = array(
            
                        
    'http:\/\/www\.'
                    
                    
    );
        
            
    $change = array(
            
                        
    ''
                    
                    
    ); 
    I get this:

    Code:
    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

  2. #2
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    /http\:www\./i

    That should work I think

  3. #3
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    2,492
    Tokens
    147

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    /http\:www\./i

    That should work I think
    Ooo right, crap i forgot the - i -

  4. #4
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    I believe preg is only used for regular expressions, but since you only want to replace http://www you can use str_replace.

  5. #5
    Join Date
    Mar 2008
    Posts
    173
    Tokens
    0

    Default

    PHP Code:
    str_replace("http://www"""$string); 

  6. #6
    Join Date
    Apr 2006
    Posts
    1,463
    Tokens
    0

    Latest Awards:

    Default

    Its something like

    PHP Code:
        mixed preg_replace     mixed $pattern    mixed $replacement    mixed $subject    [, int $limit    [, int &$count   ]] ) 

    Is int it :S

    Sorry if this didn't help.

  7. #7
    Join Date
    Mar 2008
    Posts
    173
    Tokens
    0

    Default

    Good job, you copied from PHP.net?

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

  8. #8
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    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

    PHP Code:
    <?
    $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.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •