Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2005, 11:57 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default firefox / IE

I have some problems with the following PHP code :

    $nom_aj= trim(substr($val,0,30));
    $fonction_aj= trim(substr($val,30,8));
    $nb_parts_aj= trim(substr($val,38,12));
    $salarie_aj= trim(substr($val,50,1));

      if ($nom_aj!="")
    {
        (... code ...)
    }

Under IE, the test 'if ($nom_aj!="")' acts good, but under Firefox, the trim function seems not to return a troncated string, but a string with a length of 30 characters even if $val is full of space characters. So the test always returns 'true', and 'code' is executed !

I KNOW : IE and Firefox have nothing to do whith PHP, but i tried this code a lot of times, and it always bugs with Firefox, not with IE !

Thanks !
 
Old November 4th, 2005, 03:47 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

Can you please tell the complete code?

As you said, browsers can't influence PHP, it may be having display problem! What you see in source of returned HTML?

Regards,

`~@#\^%&*/\.<.\/-|+|_!:;..=?>
Nonprofit public funds http://funds.mediasworks.org/
 
Old November 7th, 2005, 09:47 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Firstly this is a PHP question, not an HTML question, so please in the future post to the appropriate PHP forum. Rule of thumb: any time you have to post server-side code in order to explain what's going on, the server-side language is the topic you're looking to post under. Otherwise it's a shot in the dark, subscribers to the HTML forum aren't expected to know PHP, ASP, etc.

sp: troncated = truncated.

Having said that; we need more information. What is the string represented by $val? Why is it being cut up? What goal are you trying to acheive in the code.

As far as the browsers, if the values are submitted by the GET method, what does

echo "<pre>\n";
var_dump($_GET);
echo "</pre>\n";

output? If the POST method, what does var_dump($_POST) output? When you do this, also look at the dump in the HTML source code, since you won't see certain HTML entities otherwise.

You're looking for what could be different in order to find out why you are getting varying results.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 8th, 2005, 07:27 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your interest ! (and sorry for the bad topic !)
Here is the result of the var_dump($_POST) :
- under IE :
  ["lAction"]=>
  array(1) {
    [0]=>
    string(0) ""
  }
That's what i want !

- under Firefox :
  array(1) {
    [0]=>
    string(60) " "
  }

Here is the HTML code for the input field :

            <select name="lAction[]" multiple size="0">
            </select>


How must I do to have absolutely the same result in all navigators ?

(Now, I think the topic really is the HTML one's !)

Thanks again !

 
Old November 8th, 2005, 09:40 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Is that the output from HTML source? Just want to be sure there are no &nbsp; entities that you don't see.

Are you trimming the value like so

$val = trim($_POST['lAction'][0]);

before doing any other operations with it?

Also, try giving your select a default option, which could be why you have a discrepancy between browsers.

            <select name="lAction[]" multiple size="0">
                 <option value='' selected></option>
            </select>

Finally, you still haven't explained what the code does. What is it's purpose? Perhaps there is a better approach.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 8th, 2005, 10:44 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I precise : I am not the author of that code, but I have to maintain it. I have just seen there is a javascript macro which make :

    // Recopie de lassoc dans lAction
    var o;
    boxLength= document.form1.lassoc.options.length;
    for (i=0;i<boxLength;i++)
    {
        o=new Option(document.form1.lassoc.options[i].value,document.form1.lassoc.options[i].value);
        document.form1.elements["lAction[]"].options[i]=o;
    }

where
<select name="lassoc" id="lassoc" size="5" style="font-family:courier; font-size:8px;" onclick=ClickListe()>
    <option selected>&nbsp;&nbsp;&nbsp;...etc...&nbsp;</option>
</select>

(&nbsp; repeated 60 times)

We need a string of 60 spaces for display, but we want to consider it as empty in the post variable.

What could be the test, because a trim of the post variable doesn't act under firefox ?

Regards

 
Old November 8th, 2005, 10:49 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well, it's easy to discern what's happening then. IE is decoding the &nbsp; before sending it and Firefox isn't.

so, do html_entity_decode() before applying trim()


> (&nbsp; repeated 60 times)
> We need a string of 60 spaces for display, but we want to consider it as empty in the post > variable.

Why not just specify a width?

<select style='width: 400px;'>

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 8th, 2005, 12:38 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is what php manual says about html_entity_code() and trim() functions :

Note: You might wonder why trim(html_entity_decode('&nbsp;')); doesn't reduce the string to an empty string, that's because the '&nbsp;' entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset.

So, (I know this is not a wonderful solution) I use a str_replace(chr(160),"",$val). Perhaps (should be) is there a better solution ?

Thank you Rich and anshul !






Similar Threads
Thread Thread Starter Forum Replies Last Post
how with firefox akkad Javascript How-To 4 December 28th, 2006 11:45 AM
Firefox 1.5 enjoysolutions BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 March 13th, 2006 10:34 AM
Firefox brucen BOOK: Accessible XHTML and CSS Web Sites: Problem Design Solution 0 October 26th, 2005 12:38 PM
firefox Vs IE fred_brie HTML Code Clinic 1 February 22nd, 2005 04:12 PM
Firefox Hunter Linux 1 February 22nd, 2005 12:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.