832
votes
43answers
240k views
Using a regular expression to validate an email address
Over the years I have slowly developed a regular expression that validates MOST email addresses correctly, assuming they don't use an IP address as the server part. Currently the expression is:
...
57
votes
0answers
8k views
How to parse HTML with PHP? [duplicate]
Possible Duplicate:
How to parse and process HTML with PHP?
Suggestion for a reference question. Stack Overflow has dozens of "How to parse HTML" questions coming in every day. However, ...
65
votes
17answers
118k views
How to extract img src, title and alt from html using php?
I would like to create a page where all images which reside on my website are listed with title and alternative representation.
I already wrote me a little program to find and load all HTML files, ...
62
votes
15answers
78k views
PHP validation/regex for URL
I've been looking for a simple regex for URL's, does anybody have one handy that works well? I didn't find one with the zend framework validation classes and have seen several implementations.
...
102
votes
22answers
28k views
How do you implement a good profanity filter? [closed]
Many of us need to deal with user input, search queries, and situations where the input text can potentially contain profanity or undesirable language. Oftentimes this needs to be filtered out.
Where ...
31
votes
6answers
11k views
How to find all Youtube video ids in a string using a regex?
I have a textfield where users can write anything.
For example:
Lorem Ipsum is simply dummy text.
http://www.youtube.com/watch?v=DUQi_R4SgWo
of the printing and typesetting
industry. Lorem ...
5
votes
3answers
7k views
How to validate an email address in PHP [duplicate]
I have this function to validate an email addresses:
function validateEMAIL($EMAIL) {
$v = "/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/";
return (bool)preg_match($v, $EMAIL);
}
Is this okay ...
21
votes
6answers
19k views
parse youtube video id using preg_match
I am attempting to parse the video ID of a youtube URL using preg_match. I found a regular expression on this site that appears to work;
...
20
votes
2answers
15k views
How to validate an Email in PHP?
How can I validate the input value is a valid email address using php5. Now I am using this code
function isValidEmail($email){
$pattern = ...
17
votes
11answers
27k views
Remove non-utf8 characters from string
Im having a problem with removing non-utf8 characters from string, which are not displaying properly. Characters are like this 0x97 0x61 0x6C 0x6F (hex representation)
What is the best way to remove ...
25
votes
8answers
16k views
Replace URLs in text with HTML links
Here is a design though: For example is I put a link such as
http://example.com
in textarea. How do I get PHP to detect it’s a http:// link and then print it as
print "<a ...
10
votes
7answers
2k views
How to replace text URLs and exclude URLs in HTML tags?
I need you help here.
I want to turn this:
sometext sometext http://www.somedomain.com/index.html sometext sometext
into:
sometext sometext <a ...
13
votes
6answers
5k views
How to mimic StackOverflow Auto-Link Behavior
With PHP how can I mimic the auto-link behavior of StackOverflow (which BTW is awesomely cool)?
For instance, the following URL:
...
4
votes
3answers
2k views
Regexp to add attribute in any xml tags
I have well-formed xml documents into string variables. I want to use preg_replace to add a defined attribute to every xml tags.
For example replace:
<tag1>
<tag2> some text ...
3
votes
3answers
1k views
php regex to match outside of html tags
I am making a preg_replace on html page. My pattern is aimed to add surrounding tag to some words in html. However, sometimes my regular expression modifies html tags. For example, when I try to ...