<?php
function dosomething($string, $else = '') {
if (empty($else))
$string = "<b>$string</b>";
else
$string = "<i>$string</i>";
return $string;
}
$input = "Some words.
[code]some code.[/code]
More words.
[quote]some code[/quote].
Other words.";
$codetag = array('[code]', '[quote]');
$codetag_rev = array('[/code]', '[/quote]');
for ($i = 0; $i < count($codetag); $i++)
$codetag_array[] = "/([sS]*$codetag[$i])([sS]+)($codetag_rev[$i])([sS]*)/e";
$input_new = preg_replace($codetag_array, 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input);
echo "$inputn<hr>n$input_new";
// This becomes a huge mess and $2 doesn't get saved from being bold
echo "<hr><hr>";
// It does work fine if I only try it on one tag
$input_new = preg_replace($codetag_array[0], 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input);
echo "$inputn<hr>n$input_new";
// $2 is indeed saved from turning bold
?>
So my only question is - how do I do this for multiple tags?
Or, if you want, you can simply ignore everything until now and just tell me how do I turn $input into:
// Output:
<b>Some words.
[code]</b><i>some code.</i>[/code]<b>
More words.
[quote]</b><i>some code</i><b>[/quote].
Other words.</b>;
Thanks
Must-Know Topics of PHP
Can you guys list the must-know topics of PHP. I am still a learner and I am trying to cover most of the important topics in PHP.
A rank users order by points
I want to make an insert from table 'rank' , with number (rank) from the cod blow, to fild users.rank ...set @rank := 0;select @rank:=@rank+1 'rank', users.username, users.points from users order by
Will an XHTML DOCTYPE interfere with my PHP if I'm not experienced enough?
I've read this article here: http://friendlybit.com/html/why-xhtml-is-a-bad-idea/In a nutshell it says XHTML is a big no-no for non-geeks when it comes to dynamic pages i.e. PHP.Do I sidestep XHTML
Problem in OnClientClick and OnClick sync
Hi,Strange and irritating problem:
Run function every 5 mins ??
I have a function PostMessage()How can I run it every 5 mins ??
Need help with cin setw
I made a program here is my code:#include <iostream>#include <cstdlib>#include <iomanip>#include <ctime>using namespace std;int main(){ unsigned seed = 0; int randomNum; int
Getting Subdomain Name With PHP?
I want to grab the subdomain name with PHP so I can generate database queries.for example my subdomain is san-jose.mydomain.comHow would I go about grabbing the subdoman name with PHP? Thanks!
INSERT data problem!
After having an string with apostrophes ', double quotes " or any other special characters, successfully escaped through one of themany php functions availables to escape, what other
help with Get_
ok some how this is not working i am not sure what i am doing wrong here but what this does is when the user goes to Secret-Codes.php they get a menu and when they pick the phone they want to view it
unserialize help, getting errors
hi all , I got a form with 6 fields (2 input and 4 select box), when the page loads one block is shown and through javascript all the fields can be copied multiple times so I need to store the data in