Solved

Ereg_replace

Posted on 2007-11-13
3
842 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:jcbodyworks
3 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20275568
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;
?>
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20275575
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
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20275606
Firstly i would suggest using
preg_replace()
http://www.php.net/manual/en/function.preg-replace.php

that has perl compatible syntax and its faster than ereg_replace

As for regular expression syntax have a look here

http://docs.python.org/lib/re-syntax.html
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question