I know this may seem like a newbie question, but I have a problem that I need help on.
I'm wanting to compare two strings.
String1 = apples
String2 = apples, oranges
I want to test and make sure that apples is in contained in both strings. What is the best function to use?
-Newbie Dave
Comparing Strings
Moderator: General Moderators
really depends on what you're trying to achieve.
Might be string strstr ( string haystack, string needle) is sufficient
Might be string strstr ( string haystack, string needle) is sufficient
then http://php.net/strstr is what you're looking for
or http://php.net/strpos which might be slightly faster
Code: Select all
<?php
$Var1 = 'apples';
$Var2 = 'apples, oranges';
if (strstr($Var2, $Var1)!==FALSE)
{
echo 'do this';
}
else
{
echo 'do that';
}
?>Code: Select all
<?php
$Var1 = 'apples';
$Var2 = 'apples, oranges';
if (strpos($Var2, $Var1)!==FALSE)
{
echo 'do this';
}
else
{
echo 'do that';
}
?>YAHOO it worked perfectedly!!
With everyone's help with this bit of code, I now am able to write a PHP code that is able to multiple select items in a form's menu box from a MySQL database.
With everyone's help with this bit of code, I now am able to write a PHP code that is able to multiple select items in a form's menu box from a MySQL database.
Code: Select all
<?php
do {
if(strpos($row_rsLaos['s_cell'],$row_rsCellmenu['name'])!==FALSE)
{
$check = 'SELECTED';
}
else
{
$check = '';
}
echo '<option value="'.$row_rsCellmenu['name'].'" '.$check.'>'.$row_rsCellmenu['name'].'</option>';
}
while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
?>