Hello friends,
How can i prevent user to enter any url or link in contact form text area, i have tried it with this but its not working -
if (!isset($_POST['submit']) && preg_match_all('/<a.*>.*<\/a>/', $_POST['query']))
{
echo "<h1 style='color:red;'>HTML Tag Not allowed </h1>";
}
else {
//sendmail
}
Please help me
Using PHP and preg_match_all I'm trying to get all the HTML content between the following tags (and the tags also):
<p>paragraph text</p>
don't take this
<ul><li>item 1</li><li>item 2</li></ul>
don't take this
<table><tr><td>table content</td></tr></table>
I can get one of them just fine:
preg_match_all("(<p>(.*)</p>)siU", $content, $matches, PREG_SET_ORDER);
Is there a way to get all the
<p></p> <ul></ul> <table></table>
content with a single preg_match_all? I need them to come out in the order they were found so I can echo the content and it will make sense.
So if I did a preg_match_all on the above content then iterated through the $matches array it would echo:
<p>paragraph text</p>
<ul><li>item 1</li><li>item 2</li></ul>
<table><tr><td>table content</td></tr></table>
I need to delete some unicode symbols from the string '?????? ??????? ???????????? ??????????'
I know they exist here for sure. I try:
re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', '?????? ??????? ???????????? ??????????')
but it doesn't work. String stays the same. ant suggestion what i do wrong?
I am trying to create an array of things to match in a description line. So I cant ignore them later on in my script. Below is a sample script that I have been working on, on the side.
Basically I am trying to take a bunch of strings and match it against a bunch of other strings.
AKA:
asdf or asfs or wrtw in string = true continue with script
if not print this.
import re
ignorelist = ['^test', '(.*)set']
def guess(a):
for ignore in ignorelist:
if re.match(ignore, a):
return('LOSE!')
else:
return('WIN!')
a = raw_input('Take a guess: ')
print guess(a)
Thanks
Hy i have to test if a string begins with 00 or with +
Say i have the string 0090 or +41 if the string begins with 0090 return true, elseif string begins with +90 replace the + with 00 else return false
The last two digits can be from 0-9
How do i do that in php?
I hope i could explain my question clear?
Can someone explain what the 'e' flag does, or link me to somewhere that does? I couldn't find anything via google.
Example:
preg_replace("/a(b?)c/e", "search_foo_term('\$1')", $str);
var exampleURL = '/example/url/345234/test/';
var numbersOnly = [?]
The /url/ and /test portions of the path will always be the same.
Note that I need the numbers between /url/ and /test. In the example URL above, the placeholder word example might be numbers too from time to time but in that case it shouldn't be matched. Only the numbers between /url/ and /test.
Thanks!
I'm trying to use python to copy a tree of files/directories.
is it possible to use copytree to copy everything that ends in foo?
There is an ignore_patterns patterns function, can I give it a negated regular expression? Are they supported in python?
eg.
copytree(src, dest, False, ignore_pattern('!*.foo'))
Where ! means NOT anything that ends in foo.
thanks.
I want a function that replace each li with an image. This is my code:
$(document).ready(function(){
var tmphref;
var tmpname;
var str = '<a href="' + tmphref + '"><img src="http://www.somesite.com/a/' + tmpname[1] + '/avatar-small.jpg /></a>';
$('#somediv li a').each(function(){
tmphref = $(this).attr("href");
tmpname = /http\:\/\/(\w+)\.somesite\.com\//.exec(tmphref);
$(this).parent().replaceWith(str);
});
});
The image is in this specific path: www.somesite.com/a/username/avatar-small.jpg
The code above doesn't work. Any ideas?
Thank you in advance.
I'm using the Twitter API streaming to collect thousand of tweets every minute.
They need to be matched to a list of keywords (can contain spaces).
This is my current method:
$text = preg_replace( '/[^a-z0-9]+/i', ' ', strtolower( $data['text'] ) );
$breakout = explode( " ", $text );
$result = array_intersect( $this->_currentTracks, $breakout );
I chop the tweet into words, and the matches them against my current keywords.
This works well for all the keywords without a space ofc.
If I wanted to find for example "Den Haag", It won't show up, because the string is exploded into words (based on the spaces).
Any ideas about how I can do this in a quick way?
Kind regards,
Tim
What I want to do is replace the "[replace]" in input string with the corresponding vaule in the replace array. The total number of values will change but there will always be the same number in the replace array as in input string. I have tried doing this with preg_replace and preg_replace_callback but I can't get the pattern right for [replace], I also tried using vsprintf but the % in <table width="100%"> was messing it up. All help is greatly appreciated!
Replace Array:
$array = array('value 1','value 2','value 3');
Input String
$string = '
<table width="100%">
<tr>
<td>Name:</td>
<td>[replace]</td>
</tr>
<tr>
<td>Date:</td>
<td>[replace]</td>
</tr>
<tr>
<td>Info:</td>
<td>[replace]</td>
</tr>
</table>
';
Desired Result
<table width="100%">
<tr>
<td>Name:</td>
<td>value 1</td>
</tr>
<tr>
<td>Date:</td>
<td>value 2</td>
</tr>
<tr>
<td>Info:</td>
<td>value 3</td>
</tr>
</table>
2010-June-11
<remove>2010-June-2</remove>
<remove>2010-June-3</remove>
2010-June-15
2010-June-16
2010-June-17
2010-June-3
2010-June-2
2010-June-1
I'm trying to find all instances that are between the <remove> tags
This is what I have:
$pattern = "/<remove>(.*?)<\/remove>/";
preg_match_all($pattern, $_POST['exclude'], $matches);
foreach($matches as $deselect){
foreach ($deselect as $display){
echo $display."<br />";
}
}
This is what it returns:
2010-June-2
2010-June-3
2010-June-2
2010-June-3
Why is it doubling up, and how do I prevent that?
I have the following line of code which works well:
$("a.grouped_elements[href$=.jpg],a.grouped_elements[href$=.png],a.grouped_elements[href$=.gif]").fancybox();
Problem is, if the href is .JPG it doesn't work it only works with .jpg. How can I make the above case insensitive so either all caps or no caps or a mix all match for the file extension?
Thanks
i had string like this in javascript
var str = "This is my test string is Ingrédients";
the substring "Ingrédients" can be also as "Ingredients"
how to get the index of substring "Ingrédients" from the above string
by applying regular expression ( Ingr[ée]dients )
I am trying to adapt a php application to handle non-latin scripts (specifically: Japanese, simplified Chinese and Arabic). The app's data validation routines make frequent use of regular expressions to check input, but I am not sure how to adapt the \w character type to other languages without installing additional locales on the system (which I cannot rely on).
Previous developers to have worked on the app have simply added needed characters to the regexes as the number of languages we supported grew (you frequently see "[\wÀÁÂÃÄÅÆÇÈÉ... etc" in the code), but I can't really do this for all the alphabets I need to support now.
Does anybody out there have some advice on how to tackle this?
I have a static library that is compiled with gcc 3.4.2. I am building a shared library that relies on this static lib. I will be building this shared library (.so) with gcc 4.2.2. I was wondering what are the potential pitfalls of using the 3.4.2 static library in a gcc 4.2.2 shared library?
I have a string "one two 9three 52eight four", so I only want to get "one two four", because "three" starts with "9" and "eight" starts with "52".
I tried:
"(?!\d)\w+"
but it's still taking the "three" and "eight". I don't want it.
I have asp:RegularExpressionValidator with ValidationExpression="\d+{1,4}(?:[.,]\d{1,4})?" but it doesn't' work, parser throws ArgumentException:
parsing "\d+{1,4}(?:[.,]\d{1,4})?" -
Nested quantifier {.
Where is my mistake? I want to allow strings like xxxx,xxxx - from 1 to 4 digits and decimal digits are not required, e.g.: 1000, 99,99, 0,2498, etc.
sed "s/\(.*\)/\t\1/" $filename > $sedTmpFile && mv $sedTmpFile $filename
I am expecting this sed script to insert a tab in font of every line in $filename however it is not. For some reason it is inserting a t instead.. Strange..
How would I write a regular expression (C#) which will check a given string to see if any of its characters are characters OTHER than the following:
a-z
A-Z
Æ æ Å å Ø ø - '
I'm rubbish at Regular Expressions, really!
What I'd like is to split a string containing a CCS property value into an array of [string,value,unit].
For example: if I supplied the .split() method with 1px it'd return ["1px",1,"px"]. If I were to supply, similarly, 10% it'd return ["10%",10,"%"].
Can this be done?
I appreciate all your help!
How to use Regular Expression to extract the answer "Here is the answer" from a HTML webpage like this?
<b>Last Question:</b>
<b>Here is the answer</b>
..:: Update ::..
Thanks everybody!
Here is my solution by using BeautifulSoup since I'm using Python framework:
response = opener.open(url)
the_page = response.read()
soup = BeautifulSoup(''.join(the_page))
paraText1 = soup.body.find('div', 'div_id', text = u'Last Question:')
if paraText1:
answer = paraText1.next
I'm starting to learn reg exp and i'm just curious to reg exp used by the rest of the people so i can have a thread to look at and learn from. I had started with the eight listed here, i tried to play a little big with firebug and some tutorials and used some in my websites, but i'd like to know some from more experienced people. Thanks!
Hello!
I have this database table:
id | url
-----------------------------------------
1 | http://stackoverflow.com/
2 | http://www.google.com
3 | http://example.com/somepage
4 | https://another.net?id=88
5 | http://hello.org/index.php?hello=2
6 | http://google.com?q=hello+world
I need to search all fields, where URL belongs to a certain host.
For example, if I give the query 'google.com', it will return rows 2 and 6 (www is ignored).
I get the host using PHP parse_url() function.
How this SQL query would look like?