Link to home
Start Free TrialLog in
Avatar of jcbodyworks
jcbodyworks

asked on

Ereg_replace

I have a question in reference to the ereg_replace function in PHP. How exactly do you make it work and how does the syntax work? I find tons of code for this function, but I do not understand how to organize the brackets of items you want to replace. I have this simple ereg_replace function on my site that removes the $ and % and , for a blank space.

$loanamount=ereg_replace("[$%,]","",$_POST['loanamount']);

Thanks. Maybe a little tutorial on this function will do.
Avatar of Joe Wu
Joe Wu
Flag of Australia image

so you actually want to replace the $ and % character with a blank space?also the comma?

something like this then:

<?php
      $test = "\$mydkjsi % this";
      $loanamount=ereg_replace("[\$\%,]","",$test);
      echo $loanamount;
?>
ereg_replace gets three arguments, all of them separated by the commas. The first argument is the string to be replaced, the second argument is what will replace the string given on the first argument and the third argument is where it will search for it.

So, ereg_replace("something","SOMETHINGDIFFERENT","this string shows something"); will output "this string shows SOMETHINGDIFFERENT.

The brackets used there state that ANY $, % or , will be replaced by "" (a blank space)

More information here: http://www.php.net/ereg_replace

-V
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial