slit a string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vh81
Forum Newbie
Posts: 2
Joined: Sun Mar 05, 2006 6:29 pm

slit a string?

Post by vh81 »

i need some code to slit a string with some special tag

$needslit = "This is my string that contains :img: height=100 width=200 :/img: ... someone help me"; // 100, 200 isn't a fixed number, it can be any number!!

afterslit($needslit);

//$needslit: "This is my string that contians ... someone help me"
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What parts would you want returned?

:img:
some text here
:/img:

?

It sounds like you need a regular expression but I'm not sure exactly what you're asking :? :)

EDIT | I think I see what you're asking:

Code: Select all

echo preg_replace('@(.*?):img:.*?:/img:(.*)@is', '$1$2', $string);
Have a look over: viewtopic.php?t=33147
vh81
Forum Newbie
Posts: 2
Joined: Sun Mar 05, 2006 6:29 pm

Post by vh81 »

thanks, but your code doesn't do anything????

actually, i need a function that delete all [img] tag in a text string
for sample:

$string = This is my text [img:Blue hills.jpg,align=,width=700,height=525,vspace=0,hspace=0,border=1] it's contain many [img:rings.jpg,align=,width=400,height=325,vspace=0,hspace=0,border=1] i want to delete it";

i want affter processed $string will be "This is my text it's contain many i want to delete it". and two jpg file that included in that tag will be save in a array like this: $image[0] = "Blue hills.jpg" , $image[1] = "rings.jpg"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

call preg_match_all() first, then preg_replace() with:

Code: Select all

#\[img:([^\]]+?)(?:,[^\]]+?)?\]#i
Post Reply