Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP help

Options
  • 27-09-2008 7:37pm
    #1
    Closed Accounts Posts: 94 ✭✭


    I have a string, which is a url.

    I want my PHP script to simply stip the www. out of the url and remove a trailing slash if it has one.

    Can anyone help me?

    Thanks!


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness




  • Closed Accounts Posts: 94 ✭✭gnomer


    That would not be ideal for the purpose.

    What if somebody had a url like:

    http://www.google.com/www

    It would remove both of them, wouldn't it?.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    You will be matching www. including the . so I dont think this would be an issue?


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    regexp is pretty powerful you can do whatever you want with it.

    Take the first hit of www as in match for http://www. all other www's would be left happy.


  • Closed Accounts Posts: 94 ✭✭gnomer


    forbairt wrote: »
    regexp is pretty powerful you can do whatever you want with it.

    Take the first hit of www as in match for http://www. all other www's would be left happy.

    great! but what about the trailing slash? how will I remove that?

    Also how do I use regexp?


  • Advertisement
  • Registered Users Posts: 3,594 ✭✭✭forbairt


    well a search on the whole string matching for the url and (http://)*(www.)*(.*)(/)* would mean if its there you'd match for it if its not you won't.

    then you'd take the 3rd result ... and away you go ...


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    gnomer wrote: »
    Also how do I use regexp?


    Read this
    http://ie2.php.net/manual/en/function.preg-match.php


  • Closed Accounts Posts: 94 ✭✭gnomer


    Lol, sorry dude but I don't fully understand what you mean...

    I think I will have to search the net for somebody else who fixed this...


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    gnomer, i'm sorry but i'm with forbairt here.

    I gave you a link to the function that will help you exactly to extract what you need; I could write the regular expression for you in a couple of minutes but what's the point in that? you learn nothing, I waste time it's a lose/lose situation for both of us.

    Instead what that link does is gives you the information to get your head around this problem yourself, you won't become a better programmer if you just post on forums to get everything spoon fed to you.

    attempt it using the method i suggested if it doesn't work out, post back your attempt here we'll be only too glad to help, also have a read of this site: http://www.regular-expressions.info/


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    gnomer wrote: »
    Lol, sorry dude but I don't fully understand what you mean...

    I think I will have to search the net for somebody else who fixed this...

    yes you do that ...

    not understanding is fine ... not willing to learn is a wrong.

    You have a commercial blog there (well "commercial" at any rate)

    You're wanting people to basically do coding for you for free. While I've no problem helping people out ... as was just said ... this is a lose lose situation

    we've both given you advice on how to do it ... I would have thought we've been pretty helpful. Can't you try helping yourself a little bit ? and read through the link we've just given ? If you do .. and you're still stuck ... I'd assume we'll have no problems helping out.


  • Advertisement
  • Closed Accounts Posts: 94 ✭✭gnomer


    I'm sorry but I can't get my head around those! :)

    could I use if substr to get the first few characters and see if it is http://www. ?

    Also would that be any slower?


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    gnomer wrote: »
    I'm sorry but I can't get my head around those! :)

    could I use if substr to get the first few characters and see if it is http://www. ?

    Also would that be any slower?

    You've spent less than an hour ? on it ?

    yes substr may do the trick if you can guarantee the input


  • Closed Accounts Posts: 94 ✭✭gnomer


    forbairt wrote: »
    You've spent less than an hour ? on it ?

    yes substr may do the trick if you can guarantee the input

    Sorry, but what do you mean by "guarantee the input"?

    Thanks for all your help!


  • Registered Users Posts: 9,194 ✭✭✭RobertFoster


    gnomer wrote: »
    Sorry, but what do you mean by "guarantee the input"?

    Thanks for all your help!
    Basically, are you certain all input will be in the format you want; "http://www." || "www." etc. or are you likely to get the odd "j00suckdawtc0m!"


Advertisement