I need help with this preg_match script. I want to have a text that is inside a bbcode. So this would be the string: [caption id="attachment_123" align="alignleft" width="100" caption="This is the text that I want"]
How would you do this? The important thing is also, that the values like id and align wont be the same all the time. I tried something like preg_match('#\[caption(?:.*?)caption=开发者_如何学编程\"(.*?)\"\]#s',$result,$array);
Thank you for your help! phpheini
My suggestion:
Replace [
and ]
to <
and >
then convert that string to XML object using SimpleXML
and access caption
as a property of created object.
$input = '[caption id="attachment_123" align="alignleft" width="100" caption="This is the text that I want"]';
$input = str_replace(array('[', ']'), array('<', '>'), $input);
$object = new SimpleXML($input);
echo $object->caption;
Clean and easy. Regexp
and HTML
/BBCode
is painful.
精彩评论