shah Posted July 13, 2009 Share Posted July 13, 2009 Hello all, I need to find position of the last "/" in a string. strpos is not accepting "/" as an input. Kindly guide me how am i gona do this. Thanks Quote Link to comment Share on other sites More sharing options...
shah Posted July 13, 2009 Author Share Posted July 13, 2009 also, i need to escape special characters. i am using strpos and want to match the pattern ?q=, but it wont accept the ? character. I think it's a special character so kindly tell me how can i escape it. Thanks Quote Link to comment Share on other sites More sharing options...
ignace Posted July 13, 2009 Share Posted July 13, 2009 There must be something wrong with your script, strpos() certainly accepts / as a needle. if ($pos = strpos('path/to/directory', '/')) { print 'at: '. $pos; } else { print 'no pos'; } prints "at: 4" also, i need to escape special characters. i am using strpos and want to match the pattern ?q=, but it wont accept the ? character. I think it's a special character so kindly tell me how can i escape it. Thanks strpos() has no special characters: if ($pos = strpos('path/to/directory?q=hello+world', '?')) { print 'at: '. $pos; } else { print 'no pos'; } prints "at: 17" Quote Link to comment Share on other sites More sharing options...
.josh Posted July 13, 2009 Share Posted July 13, 2009 sounds more like you are using a preg_xxx or ereg_xxx function and are using / as the delimiter for the pattern (and not escaping the / in your pattern) which also explains that whole business with the question mark. In general, you would escape something by putting a \ before it. But if you want specific help, post some code. 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.