arecuk
168
17
Laravel

check for whitespace fails

Posted 9 months ago by arecuk

Hey guys,

I have external database that I connect to from laravel. This external table has a field: rsID varchar40 utf8_general_ci

The right format of rsID is 'rs123'. However, in some case based of user-error when entering new raws the ID contains a space:

' rs123' - the space at the beginning

'rs123 ' - the space at the end

The space is stored in the table and I can see it using phpmyadmin.

Then, in my laravel app I query the table and indeed I get the rsID rendered with a space.

I want to identify those rsIDs that contain space but Im having hard time with it.

when I hardcode the variable all works just fine!
$x = ' xx';
if (strlen($x) != strlen(trim($x)))
 there is space in the string!

but when I get the variable as a result of database query it fails:
foreach ($data as $rsID => $alleles):
if (strlen($rsID ) != strlen(trim($rsID )))
 although rsID contains space the condition is evaluated as false

Does any one has some idea? I've been playing with it for hours but somehow cant figure it out.

Thanks a lot, Tomas

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.