Forum Moderators: coopster

Message Too Old, No Replies

ereg problem

         

Nadeembabar

10:27 pm on Jun 10, 2005 (gmt 0)

10+ Year Member




HI
I want to assign data coming from a form to a variable. I want if $your_code exist in data coming from form then value assign to $new variable otherwise assign to $old variable but the function ereg does not recognizing the $ as a normal text, and always assign the text value to $old even $your_code exist. It works when I remove the $ from $your_code, what is worng with code, can some1 help?
############
if ($_REQUEST['title'] == "start") {
$template = $_REQUEST['text'];
if(ereg('$your_code', $template)) $new = $template;
else $old = $template . "\n" . '$your_code';
}
else error_function();
##########

Thanks in advance

jatar_k

10:32 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the single quotes around $your_code is stopping it from resolving the var, try with out them

if(ereg($your_code, $template))

Nadeembabar

10:38 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



HI jatar_k,
Thanks for reply
$ is escaped, I want to match the $your_code.

if(ereg("\$your_code", $template)) $new = $template;

Nadeembabar

10:55 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



problem solved, below is the changed script

############
if ($_REQUEST['title'] == "start") {
$template = $_REQUEST['text'];
if(ereg("[\$]your_code", $template)) $new = $template;
else $old = $template . "\n" . '$your_code';
}
else error_function();
##########

Thank you guyz for help

jatar_k

10:55 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah, nice work