?
Solved

how to replace text using posix regular expression

Posted on 2010-01-11
4
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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

771 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