Easy Green Rep

Discussion in 'PHP' started by aaron_nimocks, Oct 15, 2006.

  1. #1
    Simple question I cant seem to find the answer for.

    $path = "/$row-title/$cat_title.html";
    
    PHP:
    I want to have the forward slashes in the variable but this way or any way I have tried wont let me.

    End result of variable would be something like "/business/internet.html"

    Thanks
     
    aaron_nimocks, Oct 15, 2006 IP
  2. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $path="/".$row-title."/".$cat_title.".html";
    Code (markup):
    that would be an easy way to do it
     
    klown, Oct 15, 2006 IP
    aaron_nimocks, saadahmed007 and kemus like this.
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $path = "/" . $row-title . "/" . $cat_title . ".html";
    PHP:
    Try that.

    EDIT you damn clown, I need that green! :(
     
    T0PS3O, Oct 15, 2006 IP
    kemus and fsmedia like this.
  4. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #4
    Thats what I forgot. The periods. :)

    Thanks, repped ya
     
    aaron_nimocks, Oct 15, 2006 IP
  5. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #5
    Too bad. I need to spread more around first. :)
     
    aaron_nimocks, Oct 15, 2006 IP
  6. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #6
    But he didn't space and colour code it nicely! :(
     
    T0PS3O, Oct 15, 2006 IP
  7. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #7
    You guys beat me to it...
    And I was just within range of my first ("earned") green biscuit...
    damn!
     
    livingearth, Oct 15, 2006 IP
  8. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thats where you lost the time tops!

    Seems like we need another php contest to stir things up a bit.
     
    klown, Oct 15, 2006 IP
  9. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #9
    Well I will give you a chance too. :)

    This is what the end result is if I use that previous example with "two words" for $cat_title

    /Business/Web%20Design.html

    Now how can I replace that %20 with a - or just get rid of it all together.

    Right now my $path would = /Business/Web%20Design.html
     
    aaron_nimocks, Oct 15, 2006 IP
  10. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #10
    
    $cat_title = str_replace(" ", "", $cat_title);
    
    PHP:
    Eat that!
     
    T0PS3O, Oct 15, 2006 IP
  11. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #11
    I'll rep him for ya ;)
     
    fsmedia, Oct 15, 2006 IP
  12. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #12
    Thanks, worked like a charm.

    Wonder if I can just keep posting questions in this thread and get my first ever script done for me. :)
     
    aaron_nimocks, Oct 15, 2006 IP
  13. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #13
    $cat_title=implode(explode(" ",$cat_title));
    PHP:
    too fast for me!
     
    klown, Oct 15, 2006 IP
  14. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I benchmarked your suggestion and my solution is 43.2% faster.

    Eat that!
     
    T0PS3O, Oct 15, 2006 IP
  15. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #15
    i think your calculators broken, 2 minutes for you, 16 for me..

    edit: i was thinking of pulling an all nighter, just reread what you said and realized i need some sleep!

    I think the reason my code is slower is that the category needs time to for you to get away before the category explodes. Then it needs to put all the little pieces back together again.
     
    klown, Oct 15, 2006 IP
  16. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #16
    OK, let's call it a tie then :D
     
    T0PS3O, Oct 15, 2006 IP
    klown likes this.
  17. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #17
    The code in the first post works for me. If you are having problems it's most likely because you used a minus symbol rather than underscore in $row_title. I suspect that was a typo. ;)

    For more complex variable access within double-quoted string literals you can surround them with braces, e.g.
    $path = "/{$row_title}/{$cat_title}.html";
    Code (PHP):
    Note that in klown (post 2) and T0PS3O's (post 3) examples you should use single quoted string literals as they are slightly faster when variable embedding is not required.
     
    penagate, Oct 15, 2006 IP
  18. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I once saw a Digg article where this was debunked, or at least devalued. They did something like change all of the doubles to singles in 20K lines of code and the speed improvement wasn't noticable.

    I guess it comes down to habit and a willingness to change it, but I wouldn't do it for speed.
     
    T0PS3O, Oct 16, 2006 IP
  19. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Yeah - slightly being a trivial amount in most circumstances. Like everything it depends on how performance-intensive the particular section of code is, of course.
     
    penagate, Oct 16, 2006 IP