On Fri, 2002-02-01 at 14:27, Administrator wrote: > Yesterday I presented this problem to a local usergroup... > > // the following lines are contained in a class > // although I am echoing the value of $age from within the class > // this is only for testing during development. > // $age will be assigned to [$this->age_Range] later in the code
No bug here: you're outputting text containing a '<' to a web page, so the browser will try to interpret it as the start of a tag if it's immediately followed by a character. In your profile class, change $this->age_Range = $age; to $this->age_Range = htmlspecialchars($age); and you'll see what I mean. (You could always just use 'View source', I s'pose). Cheers, Torben > $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))"; > $age .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; > echo $age."<br>"; > Output of the echo statement looks exactly like this... > AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5)) > >----------------------------------------------------------------------------------------------- > Here is what I found: > > Now, from the above if I add white space between "...)<R..." like this "...) < R..." >everything works! > The revised assignment looks like this: > $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5) < >RIGHT(dob,5))"; > $age .= " BETWEEN '28' AND '42')"; > And echoes: > AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))BETWEEN >'28' AND '42') > >----------------------------------------------------------------------------------------------- > If you run the following code, you will see what I mean. I found this to be the case >with PHP 4.0.2 on Windows NT 4.0 and with PHP 4.0.6 on Linux. At one point I found >that echo of $age from outside the class returned the proper value regardless of >white space, now I can not re-create this. The behavior would appear to be the same >regardless of where you echo the var from. > For what it's worth... > Kevin > --------------------------------------------------------- > <?PHP > /*+------------------------------------------+ > |File: testclass.cls.php | > |By: Kevin Koons | > |On: Friday, February 01, 2002 11:34:41 AM | > +------------------------------------------+*/ > $myProfile = new profile; > $sql = $myProfile->profile1(); > echo "<B>The value of [\$age] returned by</B> >\$myProfile->profile1()<br><hr><br>".$sql."<br><hr><br><br><br>"; > echo "<B>called from class profile using</B> echo >\$myProfile->age_Range<br><hr><br>".$myProfile->age_Range."<br><hr><br><br><br>"; > $sql = $myProfile->profile2(); > echo "<B>The value [\$age] returned by</B> >\$myProfile->profile2()<br><hr><br>".$sql."<br><hr><br><br><br>"; > echo "<B>called from class profile using</B> echo >\$myProfile->age_Range<br><hr><br>".$myProfile->age_Range."<br><hr><br><br><br>"; > class profile > { > var $age_Range; > var $minAge = 28; > var $maxAge = 42; > Function profile1() { > // orig code, no white space > $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))"; > $age .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; > $this->age_Range = $age; > echo "<B>Echoed from IN class Profile, no white space</B><br><hr><br>"; > echo $this->age_Range."<br><hr><br><br><br>"; > Return ($age); > } > Function profile2() { > // added white space between "...) < RIGHT..." > $this->age_Range = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5) < >RIGHT(dob,5))"; > $this->age_Range .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; > echo "<B>Echoed from IN class Profile, white space added</B><br><hr><br>"; > echo $this->age_Range."<br><hr><br><br><br>"; > Return ($age); > } > } > ?> > -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]