Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to replace text using posix regular expression

Posted on 2010-01-11
4
Medium Priority
?
258 Views
Last Modified: 2013-12-12
Hi all,
my manager wants me to use posix regular expression to replace on text match with another
would you please send me an example since I searched php.net but the syntax I have problem with
thanks in advance
help me if you please

Regards
HG
0
Comment
Question by:mediabox
4 Comments
 
LVL 10

Assisted Solution

by:TiberiuGal
TiberiuGal earned 200 total points
ID: 26281704
hi,
is it the regexp or the php functions part you need help with?
can you send some code example you've tried if any, or the text you want to search?
0
 
LVL 12

Assisted Solution

by:jet-black
jet-black earned 200 total points
ID: 26282098
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 26282763
http://weitz.de/regex-coach/  (please ask your manager to consider a donation to keep this excellent service in business).

The exact code you need to use will be determined by the inputs and desired outputs.  Let's consider one simple example.  If you wanted to remove everything but letters and numbers from a string, you could do something like this.

That is about all we can do to help you until we know what your input data strings look like, and what you want for output.

One final thought, you might not want to use REGEX in situations where performance matters.  It can be slow and sometimes the combination of explode() strpos() substr() can give you the same results with less overhead.  Just a thought... ~Ray
// A FUNCTION TO GET A CLEAN STRING OF SPECIFIC LENGTH
function clean_string($str, $len=255)
{
    // LETTERS NUMBERS ONLY
    $regex = "/[^A-Za-z0-9]/";
    $str = trim($str);
    $str = preg_replace($regex, '', $str);
    $str = substr($str,0,$len);
    return $str;
}

Open in new window

0
 
LVL 1

Accepted Solution

by:
darianbr earned 1400 total points
ID: 26321083
http://weblogtoolscollection.com/regex/regex.php?page=3 is a great site which teaches you how to use regular expressions.

Use Ray_Paseur function and then apply what you learn from the link to the function.

Very helpful site.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

577 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