preg-match

Capitalize first letter of a string (preceded with special characters) - PHP

淺唱寂寞╮ 提交于 2019-12-04 11:22:40
I'd like to capitalize a string like: ¿"hello"? I want my function to return ¿"Hello"? I've tried with regex and preg_match, with no luck... Here it is my previous question, related with this one: "preg_match is matching two characters when it should only match one" Thank you all! You can do it using preg_replace_callback : preg_replace_callback('/^([^a-z]*)([a-z])/i', function($matches){ return $matches[1] . strtoupper($matches[2]); }, '¿"hello"?'); // ¿"Hello"? Using preg_replace_callback as said ascii-time above, but unicode compatible: echo preg_replace_callback('/^(\PL*)(\pL)/u', function

PHP - preg_match()

筅森魡賤 提交于 2019-12-04 10:17:02
Alright, so I want the user to be able to enter every character from A-Z and every number from 0-9, but I don't want them entering "special characters". Code: if (preg_match("/^[a-zA-Z0-9]$/", $user_name)) { #Stuff } How is it possible for it to check all of the characters given, and then check if those were matched? I've tried preg_match_all() , but I didn't honestly understand much of it. Like if a user entered "FaiL65Mal", I want it to allow it and move on. But if they enter "Fail{]^7(,", I want it to appear with an error. You just need a quantifier in your regex: Zero or more characters *

How major websites capture thumbnails from a link?

狂风中的少年 提交于 2019-12-04 10:16:44
When sharing a link in major websites like Digg and Facebook; it will create thumbnails by capturing main images of the page. How they catch images from a webpage? Does it included loading the whole page (e.g. by cURL) and parsing it (e.g. with preg_match) ? To me, this method is slow and unreliable. Does they have a more practical method? P.S. I think there should be a practical method for quick crawling the page by skipping some parts (e.g. CSS and JS) to reach src attributes. Any idea? They typcailly look for an image on the page, and scale it down on their servers. Reddit's scraper code

Why downloading the youtube file id does not work?

こ雲淡風輕ζ 提交于 2019-12-04 07:09:51
问题 I found the code that gets the movie id from the youtube site, the script works well natomast if the ID has a hyphen "-" the script does not get the ID from the url. I'm weak in regular expressions but still tried to convert the expression, but I can not deal with it. Can you direct me or show me what error I'm doing? Thanks My code: $links = array( 'https://www.youtube.com/watch?v=-SXKV0jDxuA', 'https://www.youtube.com/watch?v=ylfhCpi9AEU' ); foreach ($links as $link){ preg_match("#([\/|\?|&

Splitting string array based upon digits in php? [closed]

╄→гoц情女王★ 提交于 2019-12-04 07:05:22
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have a string $str = "101WE3P-1An Electrically-Small104TU5A-3,Signal-Interference Duplexers Gomez-GarciaRobertoTU5A-3-01" I want to split this string by the numbers, eg:"101WE3P-1An.... "should be first element

How can I get the current web directory from the URL?

痞子三分冷 提交于 2019-12-04 06:10:38
问题 If I have a URL that is http://www.example.com/sites/dir/index.html, I would want to extract the word "sites". I know I have to use regular expressions but for some reason my knowledge of them is not working on PHP. I am trying to use : $URL = $_SERVER["REQUEST_URI"]; preg_match("%^/(.*)/%", $URL, $matches); But I must be doing something wrong. I would also like it to have a catch function where if it is at the main site, www.example.com then it would do the word "MAIN" Edit: sorry, I've

Regex pattern using w.* not matching text starting with foreign characters such as Ä

拜拜、爱过 提交于 2019-12-04 05:39:51
I have the following regex that I have been using successfully: preg_match_all('/(\d+)\n(\w.*)\n(\d{3}\.\d{3}\.\d{2})\n(\d.*)\n(\d.*)/', $text, $matches) However I have just found that if the text that the (\w.*) part matches starts with a foreign character such as Ä , then it doesn't match anything. Can anyone help me with what the correct pattern should be instead of (\w.*) to match a string that starts with any character? Many thanks If you do want to match umlauts, then add the regex /u modifier, or use \pL in place of \w . That will allow the regex to match letters outside of the ASCII

Find the occurrence of backslash in a string

老子叫甜甜 提交于 2019-12-04 05:32:46
问题 If my string is : aud\ios , how do i check it out for the presence of \ in it? I tried using preg_match('\\' , $string) but it does not work. What's the correct way to achieve this? 回答1: For something simple as this, you don't need a regular expression. A string function like strpos() should be enough: if (strpos('aud\ios', '\\') !== FALSE) { // String contains '\' } Note that you need to escape the backslash here. If you simply write \ , then PHP considers it as an escape sequence and tries

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found

眉间皱痕 提交于 2019-12-04 03:50:01
问题 I am trying to resolve an issue I have been having with one of my wordpress plugins. This is line 666 function isUrl($url) { return preg_match("^http:\/\/[-0-9a-z\._]+.*$/i", trim( $url )); } What are your inputs on how I can resolve this warning? It's quite irritating. I can't figure it out and I've tried, researched everything! 回答1: / is missing. preg_match('/pattern/',$string); preg_match("/^http:\/\/[-0-9a-z\._]+.*$/i", trim( $url )); 回答2: As it has been said in other answers, you have to

PHP's `preg_match_all` functionality in Java

扶醉桌前 提交于 2019-12-04 01:19:04
问题 In PHP if we need to match a something like, ["one","two","three"] , we could use the following regular expression with preg_match . $pattern = "/\[\"(\w+)\",\"(\w+)\",\"(\w+)\"\]/" By using the parenthesis we are also able to extract the words one, two and three. I am aware of the Matcher object in Java, but am unable to get similar functionality; I am only able to extract the entire string. How would I go about mimicking the preg_match behaviour in Java. 回答1: With a Matcher, to get the