Jump to content

String handling problem


bentonsmith

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
Link to comment
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
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.