Get Before Character

Ask about a PHP problem here.
Post Reply
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Get Before Character

Post by FrederickGeek8 »

I'm trying to parse bbcode and there is this special img tag that allows width and height and comes in this format:
[img=500x300][/img]
How can I take 500x300 and split the string into 500 and 300? (two separate string)

Right now I have this but the number 500 and 300 for some reason are not included in the output string.
"<img style='height:".strstr("$1", 'x', true).";width:".strstr("$1", 'x').";' src=\"$2\" />"
preg_split also doesn't work. The first index of the array just contains the full string
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Get Before Character

Post by Temor »

the first thing that comes to mind would be to explode on x and remove the first 5 letters of the first index ( [img= ) and the last character in the second index ( ] ). But that might not work with what you have set up.
Post Reply