Jump to content

Archived

This topic is now archived and is closed to further replies.

bentonsmith

String handling problem

Recommended Posts

Hi All,
I am currently battling to sort out a string manipulation problem. Being new to PHP I'm sure the solution is not that difficult. Perhaps someone here can point me in the right direction.
Here is the problem.

I have the following string

[code]This is a test string for Benton's script
here is [img:445865]http://www.asite.com/testing/one.jpg[/img:445865] furthermore to this test is
the following too http://www.another.com/two.gif I need to strip this off to[/code]

I need to turn the string above into this

[code]http://www.asite.com/testing/one.jpg
http://www.another.com/two.gif [/code]

Basically stripping everything out except the two URL's!

Any help would be greatly appreciated.

Benton

Share this post


Link to post
Share on other sites
the only way i know of is if something is around it.. like those image tags are around the one url, thats basically the only way i can figure it out.

Share this post


Link to post
Share on other sites
try

$string = preg_replace('/(.*)(http(?! )*)(.)*/','\\1',$urinputstring);

it may work it may not

Share this post


Link to post
Share on other sites
I have played with trhe code now - preg_replace - works. The reason I could not use the [img] as a trigger is that some users do not use the [img] tag to post a picture. Just in case others have a similar problem - this is how i sorted it out

[code]preg_match_all("/http:\/\/?[^ ][^<]+/i",$post_text,$matches);

// Count how many eliments in the $matches array
$nor = count($matches);[/code]

After I count the number of matches in the array - I tiedied it up and whalla!

Thanks for your suggestions though

Benton

Share this post


Link to post
Share on other sites

×

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.