Skip to content
Advertisement

need preg_match_all links

i have a string like this one:

$string = "some text
  http://dvz.local/index/index/regionId/28
        http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
         http://192.168.3.192/roadmap_page.php#qwe";

need to get all links.

i tried this way: /http://(.*)[|s]?/

returns:

array(2) {
  [0] =>
  array(3) {
    [0] =>
    string(42) "http://dvz.local/index/index/regionId/28rn"
    [1] =>
    string(77) "http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.phprn"
    [2] =>
    string(41) "http://192.168.3.192/roadmap_page.php#qwe"
  }
  [1] =>
  array(3) {
    [0] =>
    string(34) "dvz.local/index/index/regionId/28r"
    [1] =>
    string(69) "stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.phpr"
    [2] =>
    string(34) "192.168.3.192/roadmap_page.php#qwe"
  }
}

EDIT 1: expect:

array(2) {
  [0] =>
  array(3) {
    [0] =>
    string(42) "http://dvz.local/index/index/regionId/28"
    [1] =>
    string(77) "http://stuff.kiev.ua/roadmap_page.php"
    [2] =>
    string(77) "http://192.168.3.192/roadmap_page.php"
    [3] =>
    string(41) "http://192.168.3.192/roadmap_page.php#qwe"
  }
  [1] =>
  array(3) {
    [0] =>
    string(34) "dvz.local/index/index/regionId/28"
    [1] =>
    string(69) "stuff.kiev.ua/roadmap_page.php"
    [2] =>
    string(69) "192.168.3.192/roadmap_page.php"
    [3] =>
    string(34) "192.168.3.192/roadmap_page.php#qwe"
  }
}

Advertisement

Answer

Try this one:

/http://([^s]+)/
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement