huge preg_replace listing, server heavy load?

Discussion in 'PHP' started by Adulu, Jan 29, 2010.

  1. #1
    $a1 = preg_replace("/keyword1/", "<a href='http://keyword.com'>keyword</a>", "$a", 1);
    $a2 = preg_replace("/keyword1/", "<a href='http://keyword1.com'>keyword1</a>", "$a1", 1);
    $a3 = preg_replace("/keyword1/", "<a href='http://keyword2.com'>keyword2</a>", "$a2", 1);
    ...........
    .........
    ....etc
    ...
    //the numbers of 1K line
    $a1000 = preg_replace("/keyword1/", "<a href='http://keyword999.com'>keyword999</a>", "$a999", 1);

    1K preg_replace line, 80KB of php file.

    server will heavy load or not?

    thank you
     
    Adulu, Jan 29, 2010 IP
  2. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This wont take much load for sure. This is just string processing. The data is already there and its not taking much resources like mysql or connection to other webpages.
     
    HivelocityDD, Jan 30, 2010 IP
  3. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much:D
     
    Adulu, Jan 30, 2010 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    Just a small observation:

    You only need to place string operators around strings, not around the variables or non-string literal values within functions.

    If you still wish to make your programming more efficient and resourceful, you may be able reduce the server load by a small amount if you look up functions and their alternatives (if any) to compare their CPU and memory usages as well as omitting any unnecessary operators.
     
    Last edited: Jan 30, 2010
    BRUm, Jan 30, 2010 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    Have a look at strpos, str_replace, substr. Most of the time they are faster than regex.
     
    Kaizoku, Jan 30, 2010 IP