SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    newlines, hyperlinks and email links

    What is the proper order to do the following:

    I have data in a mysql database that is simply text. Some things i use nl2br and other things i use a homemade function to do the email links and hyperlinks

    PHP Code:
    function makelinks($data,$br=1) {
        
    // Replace tekstlink with HyperLink
        
    $data ereg_replace('www+(\.[[:alnum:]~_-]+)+([/\.][[:alnum:]?&=~_-]+)*/*''<A HREF="http://\\0" TARGET="_blank">\\0</A>'$data);

        
    // Replace mailtext with HyperLink
        
    $data ereg_replace('[A-Za-z0-9]([A-Za-z0-9._]*[A-Za-z0-9]|())@[A-Za-z0-9]([A-Za-z0-9.\-]*[A-Za-z0-9]|())\.[A-Za-z]+''<A HREF="mailto:\\0">\\0</A>'$data);
        
        
    // Insert Break tags before newlines
        
    if ($br == 1) {
            
    $data nl2br($data);
        }
        
        return 
    $data;

    this makelinks function seems to be buggy sometimes when mixed with the html_entities function and so on. Is there anyway to simplify how to process input that lays in the database when displayed on the website?
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe i'm stating the obvious, but if i understand it correctly your problem is that when you run your homegrown function followed by html_entities, it messes up display (as it will replace all your <, > etc). how about running html_entities first and then makelinks ?
    if i totally misunderstood the problem...my apologies for naff advice...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No idea, but cheers for the ereg to change links into links... have been scratching my head all afternoon on that one...
    I swear to drunk I'm not God.
    » Matt's debating is not a crime «
    Hint: Don't buy a stupid dwarf ö Clicky


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
  •