preg-match

PHP: Remove all hyperlinks of specific domain from text

試著忘記壹切 提交于 2019-12-13 07:06:53
问题 2 things: Remove all hyperlinks that point to mydomain.com & retain all other hyperlinks that do not belong to this domain. For all the other URLs that remain, grab the value between tags and show it as ID. 1. About 1st task: I have this: $str = 'I have been searching <a href="http://www.google.com">Google</a> for all the valuable information. I have also tried <a href="http://www.yahoo.com">Yahoo</a> and I finally, ended up finding it at <font size="1">My Site <a style="color:#0000ff;font

PHP preg_match question

人走茶凉 提交于 2019-12-13 06:32:28
问题 How can I match the three words in the following string with a Perl compatible regular expression? word1#$word2#$word3 I don't know the actual words "word1, word2 and word3" in advance. I only know the separator, which is #$. And I can't use the word boundary as I have a multibyte encoding. This means for instance that the string can contain non-ASCII characters like umlauts which are not detected by the \w control character. 回答1: Try this regular expression: /(\w+)#\$(\w+)#\$(\w+)/ Edit

Preg_match for next line

瘦欲@ 提交于 2019-12-13 05:52:00
问题 There is a pattern in my texts and I need a preg_match pattern for next line. Administrative Contact: xxxx xxxxx this is like this sometimes : Admin contact: xxxxxx xxxx or admin data: xxxx xxxx Is it possible to write a regular expression for this ? I need xxxx xxxx data Thank You Guys 回答1: It looks like the common factors are: Starts with "admin" Has a : to separate the label from the data Has data until the end of a line In this case, the regex is: /admin[^:]*:\s*(.*)/i The desired data

Image prefix (url rewrite)

不羁岁月 提交于 2019-12-13 04:40:42
问题 I'm use this tutorials to add watermark on my images: http://www.reviewsforjoomla.com/forum/index.php?topic=15067.0 All JPG are correctly marked up with this htaccess rule: RewriteEngine on RewriteRule ^([^tn].*\.(jpg))$ watermark.php?image=$1&watermark=watermark.png [NC] Now, i need to apply different watermarks based on file prefix, like: AA-myimage.jpg (apply aa-watermark.png to all files with AA- prefix) BB-myimage.jpg (apply bb-watermark.png to all images with BB- prefix) There is a way

PHP: how to create an regexp to preg_match() for PT Mobile phones?

回眸只為那壹抹淺笑 提交于 2019-12-13 03:02:31
问题 i'm newer related to Regexp on PHP ... I need to create an Regexp to filter Portuguese Mobile Phones, can anybody help me and explain how i do it? (To i understand it) Rules: The integer/string must have 9chars; The first char must be a '9'; The second one can be '1,2,3,6' (Chars are separeted by commas); The other chars must be in range of '0-9'; 回答1: #9[1236][0-9]{7}# That should do it ;) Explanation: # <-- delimiter 9 <-- 9 [1236] <-- either of the chars in the brackets [0-9]{7} <-- 0-9 7

php preg match - how to get html tag?

落爺英雄遲暮 提交于 2019-12-13 02:38:00
问题 there were many threads about it, but I still need help. I need to use preg_match to get the text I need from HTML tags. the HTML is: <td> <center> <b> <font face="Arial" color="red">(I need this content)</font> </b> </center> </td> (btw. I solved my problem with domdocument, but I need to use preg_match) Please, help. Regards. 回答1: This? <?php $html = '<td> <center> <b> <font face="Arial" color="red">(I need this content)</font> </b> </center> </td>'; $matches = array(); preg_match_all('/

class.upload error preg_match() [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 02:37:18
问题 This question already has answers here : preg_match(): Compilation failed: invalid range in character class at offset (5 answers) Closed 7 months ago . I use class.upload Version 0.32 and it works correctly on my localhost server, but it does not work on my web server. The web server log file shows this error: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 7 in. PHP version on web server: 5.4.39 PHP version on localhost: 5.5.15 if (preg_match("/^([\.

validate url without www. or http://

强颜欢笑 提交于 2019-12-13 00:33:31
问题 I'm looking to validate an URL. I have already a script that validates to not allow www. and http:// but i need to also validate for .co.uk .com etc. My script won't run if they enter something like example.co.ukff . I have this for a full URL: ^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i I just need to validate the end .co.uk or .com etc. 回答1: Try This... /^http:\/\/|(www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ It's working exactly what you

empty regex matches any string

自作多情 提交于 2019-12-13 00:12:40
问题 I was trying to find a regex that matches any string! and after some search I found almost all the answers says that [\s\S] will match any string as said here or .* as said here But while playing a bit with PHP preg_match I found that an empty regex is matching any string! if(preg_match("//u", "")) echo "empty string matchs\n"; else echo "empty string does not match\n"; if(preg_match("//u", "abc")) echo "abc matchs\n"; else echo "abc does not match\n"; if(preg_match("//u", "\n")) echo "new

preg_replace to change url from relative to absolute

[亡魂溺海] 提交于 2019-12-12 21:13:22
问题 My PHP code is: $string = preg_replace('/(href|src)="([^:"]*)(?:")/i','$1="http://mydomain.com/$2"', $string); It work with: - <a href="aaa/">Link 1</a> => <a href="http://mydomain.com/aaa/">Link 1</a> - <a href="http://mydomain.com/bbb/">Link 1</a> => <a href="http://mydomain.com/bbb/">Link 1</a> But not with: - <a href='aaa/'>Link 1</a> - <a href="#top">Link 1</a> (I don't want to change if url start by #). Please help me! 回答1: How about: $arr = array('<a href="aaa/">Link 1</a>', '<a href=