Results 1 to 8 of 8

Thread: Looking for an alternative to the + symbol

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default Looking for an alternative to the + symbol

    I use tags for my articles. If you click on a tag it will display all of the articles that has that particular tag. As the number of articles increased I thought it might be useful to be able to narrow results by more than one tag as declared in the url. Fro example .php?category=css+php. The problem is that I now have an article with the tag c++.

    I now need to try to come up with some alternative to "+". I am wondering if anyone has any ideas. Here are a few that I have thought of. I could use the tilde symbol. I could separate the terms with a string of letters that are unlikely to be used in a tag. I could change the "+" so that when that particular tag is clicked on it will read as "plus" instead of "+", but only read that way when you see the url in the address bar. That last idea sounds the best, but I was wondering if anyone else had come across this problem and what you did instead.

    I remember another member on this forum a few years back working really hard to come up with a way to get the "+" to work and if I remember correctly I tried coming up with some pcre as well, but in the end it was decided that an alternative to the "+" would have to be used.
    Last edited by james438; 01-21-2013 at 06:01 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    What's urlencode('+')? And could you just use that for C++?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    The url encode value for + is %2B. I have tried several ways to get it to work, but with no luck so far. It just keeps getting translated as + instead. I want to try a few more things first, because I think I can get your suggestion to work. The space is being translated correctly so I figure the + can be made to work as well.
    Last edited by james438; 01-21-2013 at 10:17 PM. Reason: slight clarification
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,920
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    If you submit a form:

    Code:
    <form action="#">
    <input type="hidden" name="category" value="c++"> <input type="submit" value="c++">
    </form>
    This is the resulting URL:

    .php?category=c%2B%2B#

    Some browsers do not automatically add the empty hash, which is inconsequential. If you have a real URL as the action it won't happen, the action can even have its own non-empty hash.

    You can style a submit button to look like a link, set the action to whatever page you want it to go to, and you're all set.

    Edit: I just checked. In IE it loses its ClearType anti-aliasing if you style the font, so you might want to use a javascript assist to have an ordinary link submit the form, at least for IE. Or - if you don't mind having a button, use it as a submit button with it's value set as desired, as in the above.


    Or - this works out rather well cross browser, if you can live with the font:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    form.link {
    	margin: 0;
    	padding: 0;
    	display: inline;
    }
    form.link input {
    	background-color: transparent;
    	border-width: 0;
    	cursor: pointer;
    }
    </style>
    </head>
    <body>
    <form class="link"action="#">
    <input name="category" type="submit" value="c++">
    </form>
    </body>
    </html>
    However, I just checked again, this works just fine:

    Code:
    <a href="whatever.php?category=c%28%28">c++</a>
    What kind of problem were you having? If the URL is script generated, all you should have to do is either encodeURL() or encodeURLComponent() it.
    Last edited by jscheuer1; 01-21-2013 at 05:11 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    Thank you. I did not know that and was wondering why it was not working.

    One thing I was just reading that I want to try out is the php function urlencode.

    Code:
    <?php
    $u="c++";
    echo '<a href="mycgi?foo=', urlencode($u), '">c++</a>';
    ?>
    I think djr33 may have been alluding to that, but I wasn't putting what he said together fast enough. Both of your suggestions sound equally useful though.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    I have finished reading through your edits and have been trying them out. They, of course, work great. I was using + in my address to separate category tags and then exploding the various tags into an array. The tags had been escaped for security reasons. I still need to look into how that affects url encoding.

    What was happening was I was using
    Code:
    <a href="whatever.php?category=c%2B%2B">c++</a>
    and it was being expressed as whatever.php?category=c++ when I clicked on the link. Since I am unable to repeat that error I am thinking that it was the result of an error in my debugging. I think I was using html entities before djr33's response. I am not sure what I was doing wrong after his response though.

    I want to try a few of the things mentioned out and let you know what I discover.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Sorry if my post wasn't clear. I'm not certain it will work just using urlencode() because then you'll still potentially have ambiguous +'s in the URL. But you could also do some other kind of encoding before urlencode() as needed.

    In short, why not keep your current system but change C++ to some other format? Unless you need it to be obvious in the URL, I think that's the easiest answer.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    I have something in place that works now. I want it to be fairly intuitive how the url system works so that users can easily edit the url from category=php to category=php+css. Originally the thought was to replace either the + in c++ or the separating symbol of + in php+css.

    Keyboard1333 is writing an article on my website and he created the tags c++ and cmd. If someone were to search for cmd+c++ or c+++cmd (both of which will return the same results) the following url will now work:

    http://www.animeviews.com/display.php?category=c%2B%2B+cmd

    as opposed to the old error prone url of http://www.animeviews.com/display.php?category=c+++cmd

    By the way, the solution I am using is str_replace I am thankful in that I have learned more about input types and the ph function urlencode.
    To choose the lesser of two evils is still to choose evil. My personal site

Similar Threads

  1. Resolved ! symbol in a if statement
    By ggalan in forum PHP
    Replies: 5
    Last Post: 06-26-2011, 01:01 AM
  2. why this symbol used?
    By gurmeet in forum PHP
    Replies: 8
    Last Post: 01-21-2010, 12:29 PM
  3. How is the -> symbol used
    By ggalan in forum PHP
    Replies: 10
    Last Post: 01-05-2010, 12:40 AM
  4. why this symbol used in web address?
    By gurmeet in forum HTML
    Replies: 3
    Last Post: 11-25-2009, 11:31 AM
  5. How to add symbol?
    By winpeace in forum PHP
    Replies: 1
    Last Post: 11-21-2006, 09:16 AM

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
  •