Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-19-2003, 12:51 PM   #1 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
string replacement....

"lets say i have a string like this"

i want replace "have" and "string" with something like

"<a href="foo">have</a>"
"<a href="bar">string</a>"

i want to do this on a medium scale site without slowing everything down too much.

i was thinking of reading the string into an array and then compairing each element against another array that held the replacements. however, i think that will slow everything down.

anyone have any ideas of how to implement somethign like this without too much overhead?
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 11-19-2003, 01:16 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
str_replace() ?
joe_bruin is offline   Reply With Quote
Old 11-19-2003, 07:09 PM   #3 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
how much overhead will that produce when run 2000 times per page view?

that is my biggest concern... i suppose i should just write it and test it...
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 11-19-2003, 07:11 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
yeah, just run a microtime test .. i'd like to know the results!
__________________
Mike
sde is offline   Reply With Quote
Old 12-01-2003, 06:57 PM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Hm, 2000 replacements per page view? Some benchmarks would be nice to have, but that sounds like an awful lot.

Any way to get around this? ie: Can this be done on a mass-scale one time with static documents, or are you loading [somewhat] dynamic data from a db, then parsing it for display?

What about caching the content with smarty? I recently wrote a horrid little "intranet CMS" thing for work where the page content is in a DB and users link from page to page in a wiki fashion. Sorta.. eg:

Quote:
Click [login_help | here] for help with logging in.
So the data between the brackets would be replaced with: <a href="index.php?page=login_help">here</a> . (if the "| here" was left out, then "login_help" would be used as the link description) All of that is done via preg_replace().

(it also parses for %INCLUDE{"page_name"}% for inline page inclusion .. but same concept)

After that nothing else needs to be parsed until the page content is changed.

..The main thing is: what are your specific rules for replacement? How does know to link "have" to "foo" ?

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
sorting objects arrays by object properties sde Java 28 08-05-2004 05:51 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM


All times are GMT -8. The time now is 02:19 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting