I'm modifying post_insert_data['message']
$msg = str_replace('[/img]\r\n[img]', '[/img] [img]', $msg);
works as expected, but
$msg = preg_replace('#\[/img\]\r\n\[img\]#', '[/img] [img]', $msg);
doesn't.
$msg = preg_replace('#\[/img\]\s*\[img\]#i', '[/img] [img]', $msg);
doesn't work either - and is what I really want to do.
Any idea why the regex doesn't work?
Try \[/img]\n\[img]
That would make it
$msg = preg_replace('#\[/img]\n\[img]#i', '[/img] [img]', $msg);
$msg = preg_replace('#\[/img\]\s*\[img\]#i', '[/img] [img]', $msg);
should also work. (I'm assuming that you're trying to match a "close image - next line - start image" structure.)
If you don't have a regex editor,
http://myregexp.com/signedJar.html makes it easier to test things.
It doesn't work
I tried with \s and with \r?\n but for some reason it refuses to match the newline.
it's like this one: #\[/img\]\[/url\]\s*\[url=([^\]]*?)\]\[img\]#
The expression is correct, but it doesn't work. That is, it works on the site you've linked to, and it works in a simple PHP script, but it doesn't work when executed on hooks
datahandler_post_insert_post, datahandler_post_update, datahandler_post_insert_thread_post
$post->post_update_data['message'] or $post->post_insert_data['message']
I really don't understand why the str_replace matches the newline correctly, while preg_replace doesn't.
ok, finally solved. Somewhy someone decided that the hook should receive $db->escape_string($post['message']) instead of the plain message.
can this php code using to display image in index page?
what code i must use?
if {
(the message contains an image)
just take the image.
done
}
can i do that code?