Adding a base URL to links - please help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Morgan

    Adding a base URL to links - please help

    Hi there,

    I'm new to the world of PHP, so forgive me if this is a daft question.
    I've written a script which pulls some headlines from a remote site and
    displays them on my server. Trouble is, all of the links are relative
    and I need some way of adding the "http://www.foobar.com/" to the start
    of these links.

    How do I go about doing it?

    Regards,

    Kevin

  • Mike Willbanks

    #2
    Re: Adding a base URL to links - please help

    Kevin,
    [color=blue]
    > I'm new to the world of PHP, so forgive me if this is a daft question.
    > I've written a script which pulls some headlines from a remote site and
    > displays them on my server. Trouble is, all of the links are relative
    > and I need some way of adding the "http://www.foobar.com/" to the start
    > of these links.
    >
    > How do I go about doing it?[/color]

    Look into regular expressions. Search for the <a href=""> tag and check
    the contents inside. Then do a replace on the link it self.

    I would write it out for you but that doesn't help you to learn it yourself.

    A good starting point for regular expressions is: http://www.regexplib.com


    Mike

    Comment

    • Chung Leong

      #3
      Re: Adding a base URL to links - please help

      Just add a <base url="http://..."> tag in the head section.

      Comment

      Working...