Page 1 of 1

"/" how to do this within php - Forward slahes

Posted: Wed Nov 21, 2007 5:08 pm
by divx
okay, its a simple question, but I have no idea how to search for this.

How can I put a forward slash within quotes.

I have a problem, a string gets converted to "xyz\" and is then put in an sql querry, how can I detect the slash, I cant use: strpos($encPass, "\" ) > -1
Since the \ makes the quotation a non surrounding quotaion.. so what can I use to detect a forward slash?

Posted: Wed Nov 21, 2007 5:43 pm
by s.dot
You escape it.

"\\"

Posted: Wed Nov 21, 2007 5:46 pm
by phpBuddy
Use substr() http://php.net/substr
to check last char of a string
and remove if backslash

The tricky thing is that '\' has to be escaped with one: '\'

Code: Select all

<?php

// a backslash has to be escaped by one: '\'
$string = 'xyz\\';
// see if last char is '\'
// -1 means last char. 1 means length = 1 char to test
if( substr( $string, -1, 1 ) == '\\')
    // From 0 first char, to length -1
    $string = substr( $string, 0, -1 );
echo $string;

?>

Posted: Thu Nov 22, 2007 9:39 am
by feyd
rtrim() works better than substr() et al.