Jump to content

Find urls in text and show them


mysterbx

Recommended Posts

How can I make this line work?

preg_match_all("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#ise", $htmlbody, $links);

 

when i use print_r($links);

 

it return results:

 

Array ( [0] => Array ( [0] => http://txt.com/files/8452782/txt_1_1.wmv [1] => http://txt.com/files/8452702/txt_1_2.wmv [2] => http://txt.com/files/8452734/txt_2_1.wmv [3] => http://txt.com/files/8452328/txt_2_2.wmv [4] => http://txt.com/files/8452922/txt_3_1.wmv [5] => http://txt.com/files/8452796/txt_3_2.wmv [6] => http://txt.com/files/8452355/txt_4_1.wmv [7] => http://txt.com/files/8452770/txt_4_2.wmv [8] => http://txt.com/files/8452753/txt_5_1.wmv [9] => http://txt.com/files/8452802/txt_5_2.wmv [10] => http://txt.com/files/8452774/txt_6_1.wmv [11] => http://txt.com/files/8452694/txt_6_2.wmv [12] => http://txt.com/files/8452458/txt_7_1.wmv [13] => http://txt.com/files/8452795/txt_7_2.wmv [14] => http://txt.com/files/8452690/txt_8_1.wmv [15] => http://txt.com/files/8452762/txt_8_2.wmv [16] => http://txt.com/files/8452754/txt_9_1.wmv [17] => http://txt.com/files/8452751/txt_9_2.wmv [18] => http://txt.com/files/8452769/txt_10_1.wmv [19] => http://txt.com/files/8452720/txt_10_2.wmv ) [1] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => ) [2] => Array ( [0] => http://txt.com/files/8452782/txt_1_1.wmv [1] => http://txt.com/files/8452702/txt_1_2.wmv [2] => http://txt.com/files/8452734/txt_2_1.wmv [3] => http://txt.com/files/8452328/txt_2_2.wmv [4] => http://txt.com/files/8452922/txt_3_1.wmv [5] => http://txt.com/files/8452796/txt_3_2.wmv [6] => http://txt.com/files/8452355/txt_4_1.wmv [7] => http://txt.com/files/8452770/txt_4_2.wmv [8] => http://txt.com/files/8452753/txt_5_1.wmv [9] => http://txt.com/files/8452802/txt_5_2.wmv [10] => http://txt.com/files/8452774/txt_6_1.wmv [11] => http://txt.com/files/8452694/txt_6_2.wmv [12] => http://txt.com/files/8452458/txt_7_1.wmv [13] => http://txt.com/files/8452795/txt_7_2.wmv [14] => http://txt.com/files/8452690/txt_8_1.wmv [15] => http://txt.com/files/8452762/txt_8_2.wmv [16] => http://txt.com/files/8452754/txt_9_1.wmv [17] => http://txt.com/files/8452751/txt_9_2.wmv [18] => http://txt.com/files/8452769/txt_10_1.wmv [19] => http://txt.com/files/8452720/txt_10_2.wmv ) )

 

but when i enter return $links[2]; or any other number i get nothing... i just see "ArrayArrayArrray"

 

can you help me fix this preg_match_all into working line? maybe it need to be preg_match or preg replace... i dont know...

i just need to list all the links like this:

 

http://link1

http://link1

http://link1

http://link1

...

Link to comment
Share on other sites

U dun undertsand how preg_match_all works, it's doing exactly as u told it....

 

preg_match_all is returning an array, with arrays of the groups captures.

since u only have 2 groups, u will have an array of an array with 3 arrays

1st array the match string itself

2nd array the first capture group

3rd array the 2nd capture group

 

from the looks of things you want to process the 3rd array, your 2nd capture group.

return $links[2] wud return an array of each (an array)

 

but to display an item from those links

$links[2][0] wud be the first item caught

or use a

foreach($links[2] as $link)

  echo "$link<br>";

 

Link to comment
Share on other sites

works fine thanks a lot!

 

what about this,

 

$text = "Password: somethin

 

P/W

somethin2

 

pass sth";

 

preg_match_all should find all passwords until \n or \t or \r and list them in one line

 

im working on this script for a few days, I cant make it work, if i do, it works for one text, but not for other, and oppositivly

 

 

this is almost the last piece to my script :)

Link to comment
Share on other sites

almost got it...

 

preg_match_all("#([\n\s])((Password(\:|)|pw\:|Pass(\:|))[\s\n\r\t\S<][^\n\t\r]*)#ise", $fix, $pass);

 

it find's the passwords, but shows it like this:

Password somekindaword
pass: somekindaword2

 

but it should look like this:

somekindaword, somekindaword2

 

please help me, its the last component...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.