1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ho to get a specific value from an array?

Discussion in 'PHP' started by KingCobra, Oct 2, 2020.

  1. #1
    Hi, I am scraping a site to get its all url inside a div. I got multiple links from that div.

    preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $table, $match);
    
    print_r($match[0]);
    Code (markup):
    I got all links in an array. The print_r function contains the data like following. (it don't display in my page but in source code)

    Array
    (
    [0] => https://aaaa.com/wp-content/themes/jnews/assets/img/jeg-empty.png
    [1] => https://aaaa.com/wp-content/uploads/2020/10/NF-100-3-750x394.jpg
    [2] => https://aaaa.com/wp-content/uploads/2020/10/NF-100-3-750x394.jpg
    [3] => https://aaaa.com/wp-content/uploads/2020/10/NF-100-3-300x158.jpg
    [4] => https://aaaa.com/wp-content/uploads/2020/10/NF-100-3-1024x538.jpg
    [5] => https://aaaa.com/wp-content/uploads/2020/10/NF-100-3-768x403.jpg
    )
    
    Code (markup):
    I need only the second link in variable so that I can use it in my php code.
    But how can I will take the second link from the array?

    Please help.

     
    KingCobra, Oct 2, 2020 IP
  2. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    SOLVED
     
    KingCobra, Oct 2, 2020 IP
  3. faridgem

    faridgem Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    You can get the data by type the PHP eco command.
     
    faridgem, Oct 11, 2020 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Why the regex crap when you could just load it into DOMDocument and walk it? Or are they in there as plaintext and not actual href/src?
     
    deathshadow, Oct 16, 2020 IP