Page 1 of 1

Trouble with an ereg

Posted: Mon Aug 26, 2002 9:01 am
by massiveone
Here is my problem im sure its just a syntax problem but if anyone cuold help that would be greatly appreciated.
here is my line of code

if (ereg('^($searchvar).*X*[SML]$',$row['Sku'])) ( >rest of code

The problem is the variavle $searchvar is not bieng passed into the argument (or at least i think so). $searchvar is text ie r2-1001.
if i replace $searchvar with my txt string it works fine but not with the variable in there.. mmm any ideas...

Thanks
:D

Posted: Mon Aug 26, 2002 9:06 am
by volka
short example ;)

$a = 'whatever';

print( "$a"); -> whatever
print( '$a'); -> $a

using ' no replacement is done by php

trouble still

Posted: Mon Aug 26, 2002 9:27 am
by massiveone
thanks for the example but i already did that to test if the variable was stored.
and it was but in the ereg funciton its not working and insight?

Posted: Mon Aug 26, 2002 9:33 am
by volka
use a "print-debugger"

Code: Select all

...
$pattern = "^($searchvar).*X*їSML]$";
$result = ereg($pattern,$rowї'Sku'])

print('<span border="1">')
print('$searchvar = '.$searchvar);
print('<br/>$pattern = '.$pattern);
print('<br/>$row&#1111;''Sku''] = '.$row&#1111;'Sku']);
print('<br/>$result = '.$result);
print('</span>');
if ($result) &#123;
....

Posted: Mon Aug 26, 2002 2:36 pm
by Takuma
if (ereg('^($searchvar).*X*[SML]$',$row['Sku']))
^
what's . doing in here it should be \. should not it? I'm not sure but I recall a tutorial saying . should be excaped. And also I think this helps, ereg("^($searchvar)[\.]*[X]*[SML]$",$row['Sku']).

Thanks

Posted: Mon Aug 26, 2002 3:56 pm
by massiveone
Thanks for the help :D