Solved

How to build a function (PHP) which replaces....

Posted on 2009-07-14
5
180 Views
Last Modified: 2013-12-13
everything about: 0-9, a-z, A-Z, _
replaces on '' (deletes)
0
Comment
Question by:AndyPSV
  • 2
5 Comments
 
LVL 5

Expert Comment

by:dvz-
Comment Utility
I don't understand the question exactly...

You want a function that takes a string and deletes those characters?

Can you show a string to pass to the "function" and what the desired output would be ?
0
 
LVL 14

Accepted Solution

by:
profya earned 500 total points
Comment Utility

function myDelete($text)

{

	$pattern="/[0-9A-Za-z_]/";

	return preg_replace($pattern, "", $text);

}

Open in new window

0
 
LVL 9

Expert Comment

by:xBellox
Comment Utility
To replace everything that ISN'T alphanumeric and/or "_" you can use this:

$new_string = preg_replace(/[^a-zA-Z0-9_\s]/, , $string);

Like in this example:

<?php
 

$string = Here! is some text, and numbers 12345, and symbols !£$%^&;
 

$new_string = preg_replace(/[^a-zA-Z0-9_\s]/, , $string);
 

echo $new_string; // It shows: Here is some text and numbers 12345 and symbols
 

?>

Open in new window

0
 
LVL 14

Expert Comment

by:profya
Comment Utility
And to test it:
echo myDelete("123 abdx **&&++__");

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to count occurrences of each item in an array.
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…

743 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

8 Experts available now in Live!

Get 1:1 Help Now