Trouble with an ereg

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

Trouble with an ereg

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

short example ;)

$a = 'whatever';

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

using ' no replacement is done by php
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

trouble still

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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;
....
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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']).
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

Thanks

Post by massiveone »

Thanks for the help :D
Post Reply