PHP - At A Loss: Strstr
I've spent two hours comparing strings.
$string1 = $gettext['$number']; $string2 = $getstuff['url']; if (strlen(strstr($string1,$string2))>0) { print "YES<br />"; } There is my code. $string1 == aad.com $string2 == aad.com So why does it refuse to print out Yes? I am getting $string1 from an array that I created and $string2 from the database but all I want to see is $string2 has text in $string1 &/or it is identical. String1 is the haystack and String2 is the needle. I've tried every kind of tutorial possible but nothing is working. Similar TutorialsCode: [Select] $pdf->Write(5, "Title {$inv['cTitle']}, {strstr($inv['cTitle'], ':', true);}"); Code gives an error... How can I use this function correctly {strstr($inv['cTitle'], ':', true); example: cTitle = Robert 20078956 : HOT TEA strstr(cTitle) = Robert 20078956 I want to get before colon ( I've been using php's strstr() function to find data before an @ character in a string. Work fine for my local ide. I just uploaded all my files to a host to start debugging emails and it came to my attention that my hosting environment is running version 5.2.9 and strstr() isn't fully supported. Heres a bit of code from the manual to show i'm talking about Code: [Select] <?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com $user = strstr($email, '@', true); // As of PHP 5.3.0 <-- echo $user; // prints name ?> I can't use the third argument apparently. Is there another way to go about doing this? This was to match two letters together, 1 was from a post / form,another from a array. it working this way but in_array wouldnt work ... Please can you give an example of in_array, matching a posted letter and a array letter cheers. Code: [Select] <?php if(isset($_POST['submit'])){ $quostionb=array("a"); $quostiona=$_POST['quostiona']; if(strstr($quostiona,implode($quostionb," "))){ echo"<p> ansaw is: ".implode($quostionb," ")." "; }else die(); } ?> <form method="POST" action=" "> <select name="quostiona"> <option value="a">a</option> <option value="b">b</option> </select> <input type="submit" name="submit" value="send"> </form> |