SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange toruble with sibple regexp

    I have a trouble: my code doesn't work. Here is it:
    PHP Code:
     $string 'http://www.site.ru';
     
    $pattern '!http//(.*?)!';
     
    $replacement "<a href=\"http://\\1\">http://\\1</a>";
     echo 
    preg_replace($pattern$replacement$string); 
    It outputs only http://www.site.ru!

  2. #2
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you want it to output?

  3. #3
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I wrote http// instead of http://

  4. #4
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mav3n
    What do you want it to output?
    highlighted url

  5. #5
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed it to this:
    PHP Code:
     $string 'http://www.site.ru';
     
    $pattern '!http://(.*?)!is';
     
    $replacement "<a href=\"http://\\1\">http://\\1</a>";
     echo 
    preg_replace($pattern$replacement$string); 
    But it highlights only http://:
    http://www.site.ru
    Why?

  6. #6
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct is:
    PHP Code:
     $string 'http://www.site.ru';
     
    $pattern '!http://(.*)!is';
     
    $replacement "<a href=\"http://\\1\">http://\\1</a>";
     echo 
    preg_replace($pattern$replacement$string); 


Bookmarks

Posting Permissions

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