Solved

Ereg_replace

Posted on 2007-11-13
3
837 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now