SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A bad case of eregi

    I've lost the plot a bit this afternoon. Now surely this is simple - but I'm just lost.

    Lets say:
    $subject = 'Holy purple FOO phpBoy!';

    My search string is:
    $search = 'foo';

    My replace string is (not really relevent but for the sake of the example):
    $replace = 'bar';

    Now, I want a regex where 'foo' will match 'FOO' and thus 'FOO' will be replaced by 'bar'.

    I thought:
    eregi_replace($search, $replace, $subject)
    would do this for me.

    This is user submitted text I'm massaging, and I don't want to change their capitalization. If they think it r0x0rs to spell foo as fOO - that's their perogative.

    But looks like I'm all out of bar on this one

  2. #2
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works for me:
    PHP Code:
    eregi_replace"($search)""$replace"$text); 
    I have used this and similar code several times with no failures.
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. Its just not working for me

  4. #4
    Digital Warrior Renegade's Avatar
    Join Date
    Nov 2000
    Location
    Portland, OR
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would the user have to know that you uppercased it? Unless you repeat the orginal search string with the search results, they will never be the wiser
    --There's my 1.5 cents, now where is my change!?!?

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your input. It got me thinking and I've extended on your logic a little more to come up with what must surely be the generic catch-all form data processing function of all time. Enjoy!
    PHP Code:
    function processFormData() {
       global 
    $HTTP_POST_VARS;  
       
    $fp fopen("/dev/null""w");

       foreach(
    $HTTP_POST_VARS as $formData) {
          
    fwrite($fp$formData "\n");
       }

       
    fclose($fp);
       echo 
    "Your data has been successfully processed";

    And the best part is that the user will be none the wiser

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After further debugging - the problem is not with my use of eregi_replace but with my logic elsewhere.


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
  •