SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expressions

    Hi Guru's,

    Just curious if someone knows a solution for the next case:

    I want to search and replace usign the PHP function ereg_replace.

    $str = "Hello_everyone#How's life";

    I would like to know if it is possible to replace the underscore (_) character and the hex character (#) with both a different value in one call.

    ereg_replace('[_][#]', '[ ][, ]', $str); <- ofcourse this doesn't work!

    Thanks for the help!

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Found the solution

    Wasn't aware that it was also possible with str_replace().


    PHP Code:
     $a_search  = array('_id''_');
     
    $a_replace = array(''' ');
     
    $label     ucfirst(str_replace($a_search$a_replace$name)); 


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
  •