SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2004
    Location
    USA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    modify words on page?

    I'm wondering if it's possible to affect existing pages (just by entering in a function or snippet) to read the contents and replace some of the words with hyperlinks.

    Basically I'll be reading off a xml file. The xml file will have keywords and the corrosponding urls.

    I'll want to match the keywords with the page content and replace the word with a hyperlink.

    Is it possible? What do I need to look up? I guess I'm wondering if it's even possible because of the way pages load on browsers..

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    >I guess I'm wondering if it's even possible because of the way pages load on browsers..

    Do you want to do this using Javascript, on the client - or using PHP?

  3. #3
    SitePoint Addict
    Join Date
    May 2004
    Location
    USA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd prefer to use php. I know it can be done with javascript - but then the search engines don't read the links right?

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dump the xml values into a 2d array, then loop and replace.

    PHP Code:
    foreach ($items as $item)
    {
        
    $text str_replace($item[0], '<a href="'.$item[1].'">'.$item[0].'</a>'$text);



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
  •