Solved

Ereg_replace

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

680 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