1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Stop regex splitting a matched url with preg_split

Discussion in 'PHP & Perl' started by barigain, Dec 13, 2013.

  1. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    Given the following code:


    PHP:
    $regex '/(http\:\/\/|https\:\/\/)([a-z0-9-\.\/\?\=\+_]*)/i';$text preg_split($regex$note, -1PREG_SPLIT_DELIM_CAPTURE);
    its returning an array such as:


    PHP:
    array (size=4)  => string '...' (length=X)  => string 'http s://' (length=8)  => string 'duckduckgo.com/?q=how+much+wood+could+a+wood-chuck+chuck+if+a+wood-chuck+could+chuck+wood' (length=89)  => string '...' (length=X)
    I would prefer it if the returned array had size=3, with one single URL. Is this possible?

    Thank you in advance!
     
  2. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    I've solved this problem by myself. Thank you