I have a form where users can quote others using bbcode. When somebody push quote button, the textarea value is :
[quote user=User date=1348246887 post=301]
User post text
[/quote]
And now, my code to transform into a block is :
$post = preg_replace("/\[quote user=(.*) date=(.*) post=(.*)](.*)\[\/quote\]/Uis", "<div class=\"quote\"><p>Quote by \\1 at time : \\2<a href=\"index.php?subject=".$_GET['subiect']."&post=\\3\"> </a></p><span>\\4</span></div>", $post);
How can i convert the time to date into preg_replace ? In preg_replace i can’t do it, because the value of \2 is not set.
Try something like this (I added “test” inside the link, so you could see the link–not sure what you wanted there, but a non-breaking space won’t make the link visible.) I used
htmlentitiesfor security in case the “subiect” $_GET variable (which maybe you meant to be “subject”?) contained markup or quotes. And of course, you can customize the date() string first argument to your needs. Finally, I added\s+to allow for more flexible whitespacing. I also changed delimiter ‘/’ to ‘@’ so you don’t need to escape ‘/’ within the regex.Updated for older PHP compatibility: