SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <a href... > [url]

    Hi Folks,

    I have this code:

    PHP Code:
    $contact eregi_replace("\[url]([-_./a-zA-Z0-9!&%@#?,'=:~]+)\[/url]",
    "<a href=\"\\1\" class=\"content\">\\1</A>"$contact);
    $contact eregi_replace"\[url=([-_./a-zA-Z0-9!&%@#?,'=:~]+)]".
    "([-_./a-zA-Z0-9 !&%#?,'=:~]+)\[/url]",
    "<A HREF=\"\\1\" class=\"content\>\\2</A>"$contact); 
    Now I need it to change the <a href="http://...">Link</a> to [url=http://...]Link[ /url ] when it comes out of the database again, to allow the admin to edit it.

    I've been playing with the code all evening, and any assistance is greatly appreciated!

    Chris
    Last edited by Saltire; Jan 7, 2002 at 11:10.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try looking here:

    http://www.delorie.com/gnu/docs/rx/rx_toc.html

    that should help ...

    Good luck
    the neigbours (free) WIFI makes it just a little more fun

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why are you performing the translation before inserting it into the database? Wouldn't it make more sense to store the admin-editable version of the content in the database and then format it for display in HTML only when it's pulled from the database for display?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because that regexp operation takes up processing time.

    Imagine a forum like this doing it, (don't tell me it is doing that , it would increase the load on the server to search through each post and replace those tags everytime.

    IMO it's better to do it before inserting into the database and if anyone wants to edit it, you just replace it back.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Both vBulletin (these forms0 and the SitePoint.com content management system format content at display time, yes. Tags are not removed prior to vBulletin searches (e.g. if you run a search for '[php]' in these forums, you'll get quite a large result set), and the SitePoint search engine supplied by Atomz works from a cache of the HTML output of the site's content pages.

    In the grand scheme of things, regexp operations do not consume that much processing power. Just don't use regular expressions when you don't need them and you'll be fine.
    Last edited by Kevin Yank; Jan 7, 2002 at 16:16.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    SitePoint Addict TegSkywalker's Avatar
    Join Date
    Nov 2001
    Location
    USA
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by kyank
    Why are you performing the translation before inserting it into the database? Wouldn't it make more sense to store the admin-editable version of the content in the database and then format it for display in HTML only when it's pulled from the database for display?
    omg the holy one has stepped down and spoken to us

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    'Holy one'? Goodness...! Try 'always too busy one'.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  8. #8
    purple monkey dishwasher scoates's Avatar
    Join Date
    Nov 2001
    Location
    Montreal
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bah.. that's nothing..
    We peeled apples together. (-;

    S

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is true. OMG that apple crisp was gooood. I ate too much, though. :P
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  10. #10
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Captain Proton
    don't tell me it is doing that
    it is. as Kevin said. i used to think i was going to store the "final" version in the DB and not parse it each time. but freddy and others here made me realize that it's better to process it each time. one of the advantages is that you can change around your "formatting function" any time and it will affect the whole DB. that wouldn't be possible if you had "hard-coded" the final HTML in the DB.

    another thing -- how many times do i have to tell you people?! PLEASE use preg_replace() since it's twice as fast as ereg_replace()! it will take up half the processing time, and it's just better.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •