PDA

View Full Version : Conditional based on strstr()


sabret00the
03-24-2005, 08:20 AM
what's wrong with this conditional i thought i was being quite creative?


$og_personal_message = "Please Enter A Personal Message The Group Description and Group Title Will Be Automatically Included.";
$og_personal_message = trim($og_personal_message);
$personal_message = trim($personal_message);


if ((strstr($personal_message, $og_personal_message)) AND (strlen($personal_message) != strlen($og_personal_message)))
{
$include_message = TRUE;
}

it basically checks the default value of a textarea and if it's the same when the form is being processed ignores it, where as if it's been edited whether completely different or just had something added to it it will include it in it's DB actions, the strlen comparison works to perfection, however STRSTR() is a whole over matter :( i'm not sure if it's me trying to use the wrong function or just bad coding?

oh and i read php.net before i came here too :)

Marco van Herwaarden
03-24-2005, 10:41 AM
oh and i read php.net before i came here too Didn't know you could read THAT fast ;)

Back to your problem. I think your approach is not the best. What if the message is different (strstr would be false), it would not include the message.

Why not just a plain and simple:
if ($personal_message != $og_personal_message )
That would be enough to find a changed message.

noppid
03-24-2005, 11:59 AM
I'd have to agree and even submit that if that user passes anything in that var, assume it to be a change and use it. A very simple if($personal_message). Why ask for custom input if you are going to second guess them?

If they just ammend the message with the your above code, the logic would ignore it if I understand it correctly.

Do sanity checks on it if passed in like globalize at least, but not second guess their customization.