feha
asked on
URGENT, vision_to_exe function
I have developed a function to let call, execute php functions within the text content ...
The problem is i can use it or call it just once, if i call it two or more times it doesn't work ...
<?
//======================== ========== ========== ==========
function VISION_TO_EXE ($function_name = "", $sender = "")
{
// by www.vision.to
//ini_set('display_errors' , '0');
$result = true;
/*
You can use this to filter what functions can be executed ...
if(eregi("vision_to",$func tion_name) &&
$function_name && function_exists($function_ name) &&
strtolower($function_name) != "vision_to_exe")
*/
//{
if($function_name && function_exists($function_ name) && strtoupper($function_name) != "VISION_TO_EXE")
{
//if(is_array($sender))
if(isset($sender))
{
$result = call_user_func_array($func tion_name, array($sender));
}
else
{
$result = call_user_func($function_n ame);
}
//ini_set('display_errors' , '1');
return $result;
}
else
{
return "<span style=\"color:#ff0000;\"> Vision.To CMS :Error :Function :
<strong>".$function_name." </strong> Does not exist or is not allowed! </span>";
}
//ini_set('display_errors' , '1');
}
//Usage: $output = preg_replace("/[exe=([^>]* )]([^>]*)[ /exe]/mie" ,"''.VISIO N_TO_EXE(' $1','$2'). ''",$outpu t);
//======================== ========== ========== ==========
?>
I thin the problem is in :
$output = preg_replace("/[exe=([^>]* )]([^>]*)[ /exe]/mie" ,"''.VISIO N_TO_EXE(' $1','$2'). ''",$outpu t);
more info:
http://www.vision.to/CMS/Home/index.php?pid=276
Sorry these are my last points, i have to earn more :-(
This question should be in PHP ...
The problem is i can use it or call it just once, if i call it two or more times it doesn't work ...
<?
//========================
function VISION_TO_EXE ($function_name = "", $sender = "")
{
// by www.vision.to
//ini_set('display_errors'
$result = true;
/*
You can use this to filter what functions can be executed ...
if(eregi("vision_to",$func
$function_name && function_exists($function_
strtolower($function_name)
*/
//{
if($function_name && function_exists($function_
{
//if(is_array($sender))
if(isset($sender))
{
$result = call_user_func_array($func
}
else
{
$result = call_user_func($function_n
}
//ini_set('display_errors'
return $result;
}
else
{
return "<span style=\"color:#ff0000;\"> Vision.To CMS :Error :Function :
<strong>".$function_name."
}
//ini_set('display_errors'
}
//Usage: $output = preg_replace("/[exe=([^>]*
//========================
?>
I thin the problem is in :
$output = preg_replace("/[exe=([^>]*
more info:
http://www.vision.to/CMS/Home/index.php?pid=276
Sorry these are my last points, i have to earn more :-(
This question should be in PHP ...
Also make sure that you are not too greedy with the [^>]* That means that even a bracket is included in that so if you had:
[exe]param1, param2[/exe] blah blah [exe]param1, param2, param3[/exe]
You might be replacing ALL OF IT if the regex is too greedy.
To modify yours I would do this:
"/\[exe=([^>]*)?\]([^>]*)? \[/exe\]/m ie"
Mine would not need that modification since when a bracket appears it breaks out of the a-z0-9,_ requirements:
"/\[exe=([a-z0-9,_ ]*)\]([a-z0-9,_ ]*)\[/exe\]/mie"
[exe]param1, param2[/exe] blah blah [exe]param1, param2, param3[/exe]
You might be replacing ALL OF IT if the regex is too greedy.
To modify yours I would do this:
"/\[exe=([^>]*)?\]([^>]*)?
Mine would not need that modification since when a bracket appears it breaks out of the a-z0-9,_ requirements:
"/\[exe=([a-z0-9,_ ]*)\]([a-z0-9,_ ]*)\[/exe\]/mie"
ASKER
Hi Joe P and BogoJoker, thank you,
your both ansers are right ...
[exe=function_name](parame ters)[/exe ]
how could i modify regex to use it this way ?
your both ansers are right ...
[exe=function_name](parame
how could i modify regex to use it this way ?
ASKER
I tried "/\[exe=([a-z0-9,_ ]*)\]([a-z0-9,_ ]*)\[/exe\]/mie" but i get this error:
Warning: preg_replace(): Unknown modifier '\' in c:\inetpub\wwwroot\php4\CM S_UNIVERSE \Functions \bbcode_fu nc.php on line 96
thats the line for regex
Warning: preg_replace(): Unknown modifier '\' in c:\inetpub\wwwroot\php4\CM
thats the line for regex
ASKER
remmoved the error
$content = preg_replace("/\[exe=([a-z 0-9,_ ]*)\]([a-z0-9,_ ]*)\[\/exe\]/mie","''.VISI ON_TO_EXE( '$1','$2') .''",$cont ent);
but this does not work ...
$content = preg_replace("/\[exe=([a-z
but this does not work ...
ASKER
I mean it does not work at all ...
Could you show an example of what $content is? Maybe echo $content; and paste the result here.
I noticed that I forgot to escape the / in /exe, you fixed the problem on your own. =)
Also did you try keeping the [^>]?
Joe P (I am BogoJoker) =)
I noticed that I forgot to escape the / in /exe, you fixed the problem on your own. =)
Also did you try keeping the [^>]?
Joe P (I am BogoJoker) =)
ASKER
this is what i use now:
$content = preg_replace("/\[exe=([a-z 0-9,_ ]*)\]([a-z0-9,_ ]*)\[\/exe\]/mie","''.VISI ON_TO_EXE( '$1','$2') .''",$cont ent);
and content to be parsed:
Executing the functions from content:
[code]
Some text here ....
[exe =my_function_name]paramete r1,pramete r2,paramet er3[/ exe]
Another text here ...
[/code]
LIVE TEST:
[code] [exe =date]Y-m-d[/ exe] [/code]
Date : [exe=date]Y-m-d[/exe]
Problems:
This function can only be called once from the same content.
If you have any idea why, please use this comment's section.
Thank You
This is not parsing at all ...
see result at the bottom of content
http://www.vision.to/CMS/Home/index.php?pid=276
Date : [exe=date]Y-m-d[/exe]
Should echo date ... id does with my orignal regex ...
$content = preg_replace("/\[exe=([a-z
and content to be parsed:
Executing the functions from content:
[code]
Some text here ....
[exe =my_function_name]paramete
Another text here ...
[/code]
LIVE TEST:
[code] [exe =date]Y-m-d[/ exe] [/code]
Date : [exe=date]Y-m-d[/exe]
Problems:
This function can only be called once from the same content.
If you have any idea why, please use this comment's section.
Thank You
This is not parsing at all ...
see result at the bottom of content
http://www.vision.to/CMS/Home/index.php?pid=276
Date : [exe=date]Y-m-d[/exe]
Should echo date ... id does with my orignal regex ...
Oh. well Then try this:
$content = preg_replace("/\[exe=([^\] ])*\]([^\] ]*)\[\/exe \]/mie","' '.VISION_T O_EXE('$1' ,'$2').''" ,$content) ;
That matches both [exe] blocks in this:
[code] [exe=date]Y-m-d[/exe] [/code]
Date : [exe=date]Y-m-d[/exe]
Notice that you cannot have a space between exe and = but you can have spaces after the =. Also same with [/ exe] should have no spaces.
Also sorry it took so long for me to post this. I had this code about 2 hours ago but I lost Wireless Internet Temporarily.
Joe P
$content = preg_replace("/\[exe=([^\]
That matches both [exe] blocks in this:
[code] [exe=date]Y-m-d[/exe] [/code]
Date : [exe=date]Y-m-d[/exe]
Notice that you cannot have a space between exe and = but you can have spaces after the =. Also same with [/ exe] should have no spaces.
Also sorry it took so long for me to post this. I had this code about 2 hours ago but I lost Wireless Internet Temporarily.
Joe P
ASKER
[code] [exe =date]Y-m-d[/ exe] [/code]
there are spaces just to show code not to execute :-)
in order to present code i must make some solution
example putting [code] [exe*=date]Y-m-d[/*exe] [/code] than replace them with '' :-)
there are spaces just to show code not to execute :-)
in order to present code i must make some solution
example putting [code] [exe*=date]Y-m-d[/*exe] [/code] than replace them with '' :-)
ASKER
$output = preg_replace("/[exe=([^>]* )]([^>]*)[ /exe]/mie" ,"''.VISIO N_TO_EXE(' $1','$2'). ''",$outpu t);
gives Date : Vision.To CMS :Error :Function : e Does not exist or is not allowed!
gives Date : Vision.To CMS :Error :Function : e Does not exist or is not allowed!
Well yes that should fail. Because that one does not have the ? marks.
1) $output = preg_replace("/[exe=([^>]* ?)]([^>]*? )[/exe]/mi e","''.VIS ION_TO_EXE ('$1','$2' ).''",$out put);
should work. (as long as the name or the params dont have the '>' symbol)
2) $output = preg_replace("/\[exe=([^\] ])*\]([^\] ]*)\[\/exe \]/mie","' '.VISION_T O_EXE('$1' ,'$2').''" ,$content) ;
should work.
Joe P
1) $output = preg_replace("/[exe=([^>]*
should work. (as long as the name or the params dont have the '>' symbol)
2) $output = preg_replace("/\[exe=([^\]
should work.
Joe P
Correction to number 1, I copied and Pasted what you wrote which had other bugs:
1) $output = preg_replace("/\[exe=([^>] *?)\]([^>] *?)\[\/exe \]/mie","' '.VISION_T O_EXE('$1' ,'$2').''" ,$output);
1) $output = preg_replace("/\[exe=([^>]
ASKER
Sorry none of them works , no parsing ...
Hmm. Then I really have no idea. In My regex tester it matches the blocks of [exe] perfectly. I really don't know why it doesn't work there.
Joe P
Joe P
ASKER
i get Warning: preg_replace(): Unknown modifier ']'
ASKER
the original works in multiple $content = preg_replace("/\[exe=([^>] *)\]([^>]* )\[\/exe]/ mie","''.V ISION_TO_E XE('$1','$ 2').''",$c ontent);
called several times works ok
called several times works ok
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how can i modify
$content = preg_replace("/\[exe=([^>] *)\]([^>]* )\[\/exe]/ mie","''.V ISION_TO_E XE('$1','$ 2').''",$c ontent);
to use parameters as [exe=myfunction]('1','2',' 3')[/exe] looks more natural ...
$content = preg_replace("/\[exe=([^>]
to use parameters as [exe=myfunction]('1','2','
ASKER
Just i wont work needs to be mie or ise else will not execute function VISION_TO_EXE ?!
If you want: (assuming 1, 2, and 3 are the parameters)
[exe=myfunction]('1','2',' 3')[/exe]
// Find the content
$content = preg_replace("/\[exe=([^>] *?)\]\(([^ >]*?)\)\[\ /exe\]/i", "''.VISION _TO_EXE('$ 1','$param s').''",$c ontent);
// Once you have your params you would do something like:
$params = explode(',', $theInputs);
// So $params[0] will be '1'
// And $params[1] will be '2'
The regex is very complex because the (, ), [, ], and / symbols all have a meaning already in regular expressions. That means in the regex you want if you really want one of those characters to appear you have to escape it. Gets very teadious.
Joe P
[exe=myfunction]('1','2','
// Find the content
$content = preg_replace("/\[exe=([^>]
// Once you have your params you would do something like:
$params = explode(',', $theInputs);
// So $params[0] will be '1'
// And $params[1] will be '2'
The regex is very complex because the (, ), [, ], and / symbols all have a meaning already in regular expressions. That means in the regex you want if you really want one of those characters to appear you have to escape it. Gets very teadious.
Joe P
ASKER
Thanks but i have already in my funcion
$result = call_user_func_array($func tion_name, array($sender));
this works with unlimited parameters ...
i don't like :$params = explode(',', $theInputs);
anyway it works great as is thanks a lot for your help :-)
$result = call_user_func_array($func
this works with unlimited parameters ...
i don't like :$params = explode(',', $theInputs);
anyway it works great as is thanks a lot for your help :-)
Sure no problem =)
ASKER
Here is working online
http://www.vision.to/CMS/Home/index.php?pid=276
and credits to you :-)
at the bottom there is Live execution ...
http://www.vision.to/CMS/Home/index.php?pid=276
and credits to you :-)
at the bottom there is Live execution ...
"/\[exe=([^>]*)\]([^>]*)\[
Also may I ask why your code between [exe] and [/exe] can be any character but > symbol?
You could change [^>] to allow [a-z0-9,_ ] letters, numbers, spaces, commas, and underscores.
Joe P