Amy Neville Amy Neville - 1 year ago 102
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 Source
if (substr(rtrim($link), -1) != "?") { 
  // Do stuff

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download