Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
strcmp - Baffled by a user's comment
Old 08-02-2010, 11:16 AM strcmp - Baffled by a user's comment
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I found a user reply below about the strcmp() function in PHP, and I am baffled by why this would be. Anyone understand the reason why mixing quoting styles on an HTML form would fail the strcom comparison?

Source: http://www.php.net/manual/en/function.strcmp.php#50151

Quote:
Code:
When using strcmp to compare results received from a form, keep in mind that the way you decide to encapsulate the value of the form will have an effect on your strcmp() results.

Example:

<input type="post" name="user[0]" value="abc">
<input type="post" name="user[1]" value='abc'>

strcmp() will not return the values sent from this form as "0".

However, by using single-quotes or double-quotes to encapsulate BOTH values, strcmp() will return a "0" result. 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-02-2010, 11:51 AM Re: strcmp - Baffled by a user's comment
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Have you verified this? I've never heard of it personally. Could it have something to do with "post" not being a valid value for the type attribute? Also, shouldn't the value of the name attribute just be user[] rather than user[0] or user[1]?

Edit:
It just occurred to me that if this is true it may be browser dependent since it has to do with how the form data is sent to the server. PHP wouldn't even be aware of which type of quote is used. Checking the value of each character in the string should reveal if there is a difference between the two strings:
PHP Code:
$strings $_POST['user'];
foreach(
$strings as $str)
{
    
$arr = array();
    
$i 0;
    
    while(isset(
$str[$i]))
    {
        
$arr[] = ord($str[$i]);
        
$i++;
    }
    
    
print_r($arr);

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 08-02-2010 at 12:00 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-02-2010, 11:59 AM Re: strcmp - Baffled by a user's comment
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Good observation...
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to strcmp - Baffled by a user's comment
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11790 seconds with 12 queries