Jump to content


Photo

String handling problem


  • Please log in to reply
3 replies to this topic

#1 bentonsmith

bentonsmith
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 August 2006 - 02:30 AM

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

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

I need to turn the string above into this

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

Basically stripping everything out except the two URL's!

Any help would be greatly appreciated.

Benton

#2 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 22 August 2006 - 03:46 AM

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.

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 22 August 2006 - 09:23 AM

try

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

it may work it may not
follow me on twitter @PHPsycho

#4 bentonsmith

bentonsmith
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 August 2006 - 01:00 PM

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

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

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

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

Thanks for your suggestions though

Benton





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users