homer.favenir Posted May 16, 2008 Share Posted May 16, 2008 hi to all, i have a simple question. how can i ignore "\" from this string? \24 HOUR TELEPHONE ACCESS\ thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 16, 2008 Share Posted May 16, 2008 What do you mean by ignore? You can remove the slashes with str_replace(): <?php $str = str_replace('\\', '', $str); ?> Edit: Forgot to escape the backslash. Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted May 16, 2008 Author Share Posted May 16, 2008 sorry i forgot to post my script my script is this if(preg_match("/[0-9]/", $strno)) if it see a digit it will accept the string, but when it sees a \24 HOUR TELEPHONE ACCESS\ it also accepts it, i dont need this string with "\" thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 16, 2008 Share Posted May 16, 2008 You're not being very clear. What do you want to accept? Your code currently accepts a string containing a digit (i.e. the string can contain anything else too). Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted May 16, 2008 Author Share Posted May 16, 2008 ok thanks for the reply my script is if(preg_match("/[0-9]/", $strno) && strpos($strno, "\\")! == false) and it return all string starting with "\" and i dont want that i want all string that isnt starting with "\" thanks! Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 16, 2008 Share Posted May 16, 2008 <?php if (preg_match("/[0-9]/", $strno) && strpos($strno, "\\") === false) ?> Will accept any string containing a digit (still don't get why you wanna do this check), not containing a backslash (anywhere). Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted May 16, 2008 Author Share Posted May 16, 2008 in this script if (strpos($strno, "\\") === false) how can i ignore also "["? thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 16, 2008 Share Posted May 16, 2008 <?php if (preg_match('/[0-9]/', $strno) && !preg_match('/[\[\\\\]/', $strno)) ?> Will accept any string containing a digit and not containing [ and \. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.