Amy Neville Amy Neville - 27 days ago 8
PHP Question

Check if last character is a question mark

How do I check if the last character in a string is a question mark (?) using php?

This is my current attempt but it doesn't seem to work unfortunately:

if (substr(strrev(trim($link)),0,0) != "?")
{

}

Answer
if (substr(rtrim($link), -1) != "?") { 
  // Do stuff
}

Giving a negative start value to substr() makes it count from the end instead of the beginning.

Comments