Page 1 of 1
Find - in a word
Posted: Fri Apr 17, 2009 12:57 pm
by xionhack
Hello. I want to make a function that will store a string in a variable. If there is a dash (-) in the string, it will set the variable to NULL, if it has no dashes then it will store that string in the variable. How can i do that? Thanks!
Re: Find - in a word
Posted: Fri Apr 17, 2009 1:54 pm
by koen.h
xionhack wrote:Hello. I want to make a function that will store a string in a variable. If there is a dash (-) in the string, it will set the variable to NULL, if it has no dashes then it will store that string in the variable. How can i do that? Thanks!
you can use something like this:
Code: Select all
$variable = strrpos($string, "-") ? $string : null;
Re: Find - in a word
Posted: Fri Apr 17, 2009 1:59 pm
by requinix
koen.h wrote:Code: Select all
$variable = strrpos($string, "-") ? $string : null;
Almost.
Code: Select all
$variable = (strpos($string, "-") !== false) ? null : $string;