SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict Brian Asselin's Avatar
    Join Date
    Oct 2000
    Location
    New hampshire
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Spaces in String?

    Can I put spaces in strings? If so do I need to do anything special? Here's the deal, I'm doing something to make my life easier, I'm making all contact links fill in the subject on my form script automatically, here's and example of what I'm doing:

    <a href="contact.php?why=Submit&what=News&which=ConcertDates">Submit Concert Dates</a>

    Now I was just wondering if and how to put spaces in the string so it would be like this:

    <a href="contact.php?why=Submit&what=News&which=Concert Dates">Submit Concert Dates</a>

    Can I do that or should I just make extra fields like which1 which2 etc..?

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably best to do something like this Concert_Dates

    the $info = str_replace ("_", " ", $String);

    That will give you back your spaces.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using str_repalce(" ", "_", $str) is th wrong approach sine you will need to pull the underscores off in the processing, it would be much better to use urlencode to fill the spaces with + signs, that way you have to do nothing on the following pages to get the variables to look like they started. For instance

    <a href="contact.php?why=Submit&what=News&which=Concert+Dates">Submit Concert Dates</a>

    On the next page $which would look like "Concert Dates". To do this simplky manually put them in therre or run $var = urlencode($var); before using the var in a link.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By default you should use plus signs instead of spaces. Use url_encode() to do this

    Sean

    Edit:

    freddy beat me!
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And its urlencode() not url_encode()
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought it had the underscore, in fact I have got a book that includes it! I'll have to buy the ultimate guide to PHP by freddydoesphp, can't argue with a name like that

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you got ripped off on that book:

    http://www.php.net/manual/en/function.urlencode.php
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apart from this the book is great, I did check the manual after you posted. So what do you think take my pen to my book or ask Zend to change the function name?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    code addict Abstraction's Avatar
    Join Date
    Apr 2001
    Location
    Des Moines, IA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    %20 ?

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    %20 is what you would get by running rawurlencode() and would work the same way.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can't you use a space itself in the link? i thought the browser would convert it to a "+" just as when you submit a GET (or POST) form. and then PHP takes care converting to the real characters like a space doesn't it?

    EDIT: i just tried it with regular spaces, and it's that way when it comes into the PHP script.
    Last edited by DR_LaRRY_PEpPeR; Aug 13, 2001 at 15:21.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •