0

Hi guys,

I accidently inserted " " into one column in mysql database. Column has one char length space as it is expected after insertion. However, in php code, I can not do this:

None of these returns Yes.

if(substr($data, 0, 1) == " "){
 echo "Yes";
}
if(substr($data, 0, 1) == " "){
 echo "Yes";
}
if(substr($data, 0, 1) == ""){
 echo "Yes";
}

Only this return Yes. This is not efficient because any of a,b,c,t,w,g,u,o,h ... could be yes as well.

if(is_string(substr($data, 0, 1))){
 echo "Yes";	
}

Please help
Thanks in advance

6
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by thebreadguru
0

Hi veledrom,

I did not understand your question. Could you please rephrase it?

Best Regards,

- Pedro Rubini

Edited by prubini87: n/a

0
if(stripos('cc'.$data,' '))
{
    echo 'yes';
}

//cc or any text is added in front because
//stripos($data,' ') will always return 0 ie. position of the string

Edited by Reverend Jim: Fixed formatting

0

Hi Pedro,

This is what I Post to next script:

<input type="text" name="mytext" value="<?php echo "&nbsp;"; ?>" />

In the next script:
Insert $_POST["mytext"] into a table in database.

When you check the relevant column in database, obviously you will see a space(1 char length) for it.

Now how it is done to check whether it is a space or not. Three examples I showed in first threat doesn't work.

Thanks

0

Hi veledrom,

Try searching for the HTML character entity for space.

if ($_POST["mytext"] == "&# 32;"{       // remove the space between &# 32.  I inserted the space so it would show.
echo "Is a space";
}
else{
echo "Is NOT a space";
}

Zagga
p.s. I didn't read your other post so I don't know what has been suggested before. (A good reason to not double post).

Edited by Zagga: n/a

0

&nbsp; is actually 6 characters not one.
use this

$data = str_replace('&nbsp;', ' ', $data)
if(substr($data, 0, 1) == " ")
{
 echo "Yes";
}
if(substr($data, 0, 1) == "")
{
echo "Yes";
}
0

If the &nbsp; was in a text field being returned as post var (it is a single character)

try this

$nbsp = chr(160); // the dec value for a HTML &nbsp;
$data = str_replace($nbsp, " ", $data) // will turn the &nbsp; into a standard space

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.