Jump to content


Popular Content

Showing content with the highest reputation on 12/30/2018 in all areas

  1. 1 point
  2. 1 point
    1. I don't know where you came up with 10. 2. You need to check the return value from strncasecmp. Take another look at my post.
  3. 1 point
    if (...) { makes the decision about whether to include the item from the XML in the search results. The part inside it needs to be true. stristr(..., ...) What the stristr function is effectively doing is checking if the first argument (a string) contains the second argument (also a string). It doesn't technically return true (or false) like the if expects, but it's close enough that PHP allows it. What you want is not "contains" but "starts with". Unfortunately PHP doesn't have a "starts with" function, but the strncasecmp I linked comes close: it takes two strings and compares the first few characters (you decide how many) to see if they match. The "n" means it compares a length you want, and "case" meaning it's case-insensitive (like the "i" in "stristr" means it's case-insensitive... yeah, one is "case" and one is "i", that's just the way it is). The function returns a number that measures how the two compare, and that number is 0 if they are the same. Since you want "starts with", the length you need to compare is the length of the string you are searching for. "If the first (length of $q) characters are the same...". strlen is the function to get the length. So you need to: - Keep the overall if(...) structure - Use strncasecmp instead of stristr, with the first two arguments being the two strings to compare (it doesn't actually matter which is which) and the third being the length to compare - Use strlen with $q for the length - Check that the strncasecmp function returns a number == 0 Give that a shot, and if you have problems then post what you came up with and a description of what's not working.
  4. 1 point
    if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { That is the bit to check if the string (the first argument) contains the desired letter/string (second argument). That's what you need to change. I suggest strncasecmp; the length to check should be the length of $q, not the ->nodeValue.
This leaderboard is set to New York/GMT-05:00
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.