Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. for($data as $key=>$value){
  2. print_r($value);
  3. }
  4.  
  5. 'Hello. I have two dots. Please replace them!'
  6.  
  7. 'Hello_ I have two dots_ Please replace them!'
  8.  
  9. $text='Hello. I have two dots. Please replace them!';
  10.  
  11. echo IHateStrReplace(".","_",$text);
  12.  
  13. function IHateStrReplace($replace_from,$replace_to,$input)
  14. {
  15. $result="";
  16.  
  17. for($i=0;$i<strlen($input);$i++)
  18. {
  19. $result.= ($input[$i]==$replace_from)?$replace_to:$input[$i];
  20. }
  21.  
  22. return $result;
  23. }
  24.  
  25. $var = 'Hello. I have two dots. Please replace them!';
  26. echo preg_replace('#.#', '_', $var);
  27.  
  28. foreach($data as $key => $value){
  29. $data[$key] = preg_replace('/./', '_', $value);
  30. }
  31.  
  32. print_r($data);
  33.  
  34. $original_string = 'Hello. I have two dots. Please replace them!';
  35. $exploded_string = explode('.' , $original_string);
  36. $new_string = implode('_' , $exploded_string);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement