Solved

Ereg_replace

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

757 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

21 Experts available now in Live!

Get 1:1 Help Now