bentonsmith Posted August 22, 2006 Share Posted August 22, 2006 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.jpghttp://www.another.com/two.gif [/code]Basically stripping everything out except the two URL's!Any help would be greatly appreciated.Benton Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 22, 2006 Share Posted August 22, 2006 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. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 22, 2006 Share Posted August 22, 2006 try $string = preg_replace('/(.*)(http(?! )*)(.)*/','\\1',$urinputstring);it may work it may not Quote Link to comment Share on other sites More sharing options...
bentonsmith Posted August 22, 2006 Author Share Posted August 22, 2006 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 thoughBenton Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.