In PHP, how to add underscore between two variable names

I have some fields called DB picture1_en picture2_en … picture1_de picture2_de … picture1_it picture2_it Yes, it could have been implemented another way, but I can’t change the implementation. Suppose I have a variable called $lang that contains “de” or “en” or “it” Now, if I want to print the value, I can use: for($i=1; $i<=10; ++$i) echo $r["picture$i_$lang"]; The problem is that PHP interprets the underscore as part of the variable name (for example, it interprets it as “$i_”). I’ve tried escaping the underscore in a lot of crazy ways, none of which work. Of course, I can do it echo $r[“picture”.$i.”_”.$lang]; But I’m wondering if there’s a way to force PHP to interpret the “_” as a string literal, rather than part of a variable name. 1>Scuzzy..: You can use curly braces to delimit variable name boundaries in strings (double quotes only) $r[“picture{$i}_{$lang}”]; or $r[“picture${i}_${lang}”]; http://php.net/manual/en/language.types.string.php Complex (curl) syntax Any scalar variable, array element or object property that has a string representation can be included by this syntax. Just write the expression in the same way as outside the string, and wrap it in { and }. Since { cannot escaped, so this syntax is only recognized if $…

In php, use the str_pad function to generate product numbers in the form of digital increments [PHP]

In php, use the str_pad function to generate product numbers in the form of digital increments [PHP]

Backend Development | PHP Tutorial str_pad, digital increments, product number back-end development-php tutorial solution: $str=”QB”.str_pad(($ maxid[0][“max(id)”]+1),5,”0″,STR_PAD_LEFT ); U site source code, how vscode becomes Chinese version, check gcc on ubuntu, understand the working principle of tomcat, crawler collects numbers, PHP implements oauth, which company is good for SEO optimization of the whole site lzw where $maxid[0][“max(id)”]+1) is to use the max function to find the value with the largest ID from the database, ID is the primary key, will not repeat. Ant fan game source code download, unable to enter ubuntu boot, web crawler Jingdong comment, how to judge the strings are not equal in php, Pingtouge seolzwstr_pad() function pads the string to the specified length. 33hao v5.2 source code, vscode to open other files, how to reset ubuntu, Sina cloud tomcat, sqlite to check field length, which languages ​​crawlers can use to implement, fast money php, Suzhou seo promotion software, mobile phone enterprise wap website, web chat room open source ,Lzw syntax of high-end atmospheric dream weaving template str_pad(string,length,pad_string,pad_type) ParameterDescriptionstringRequired . Specifies the string to fill. lengthRequired. Specifies the length of the new string. If the value is less than the length of the original string, nothing is done.…

In php, the method code of replacing characters according to the specified identifier and length

In php, the method code of replacing characters according to the specified identifier and length

Backend Development | PHP Tutorial php back-end development-php tutorial cf Jinding auxiliary source code, how to insert a box in vscode, rename the ubuntu host, install tomcat6 from source code, jail python reptiles, PHP packaging app tutorial , What is the difference between seo and sem lzw This article brings you the content of the method code for replacing characters according to the specified logo and length in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you help. Marriage web page source code, vscode debugging vins, svn visualization of ubuntu system, tomcat uses svn, sqlite to rename tables, how to write picture upload plug-ins, one-click formation of front-end framework, green software crawlers appear at home, php image management, Luanping optimization seo, Comment website source code, webpage video source code, registration login page html template lzw /** * replace characters according to the specified logo and length* @param $str * @param int $start the number of digits starting* @param int $end Number of reserved digits * @param string $mode * @return mixed */function _str_repeat($str=null, $start = 4, $end = 4, $mode = ‘*’){ if(!empty($str )){ $length = mb_strlen($str,’utf8′)-$start-$end; $repeat…

In php, the code to generate the Thunder Express whirlwind link from the address

function zhuanhuan() { $urlodd=explode(‘//’,$_GET[“url”],2);/ //Divide the link into 2 paragraphs, //The first paragraph is the first paragraph, and the second paragraph is the second paragraph $head=strtolower($urlodd[0]);//PHP is case sensitive , first uniformly convert to lowercase, otherwise there will be HtTp: or ThUNDER: This kind of weird writing is not easy to deal with $behind=$urlodd[1]; if($head==”thunder:”){ $url=substr(base64_decode($behind), 2, -2);//base64 decryption, remove the front AA and the back ZZ }elseif($head==”flashget:”){ $url1=explode(‘&’,$behind,2); $url=substr(base64_decode($url1[0]), 10, -10 );//base64 decryption, remove the [FLASHGET] after the front }elseif($head==”qqdl:”){ $url=base64_decode($behind);//base64 decryption span> }elseif($head==”http:”||$head=”ftp:”||$head==”mms:”||$head==”rtsp:”||$head==”https:”){ $url=$_GET[“url”];//Regular addresses only support http, https, ftp , mms, rtsp transfer protocol, there seem to be few other places, like XX network disk is actually based on base64, but some of them cannot be downloaded after decryption }else{ echo “This page temporarily does not support this protocol”; } return $url; } if($_GET[“url”]!=NULL){ $url=zhuanhuan($_GET[“url”]); $url_thunder=”thunder://”.base64_encode(“AA”.$url.”ZZ”);//base64 encryption, the same as the following 2 $url_flashget=”Flashget://”.base64_encode(“[FLASHGET]”.$url.”[FLASHGET]”).” &aiyh”; $url_qqdl=”qqdl://”.base64_encode($url); } jb51.net Please enter the normal link or Thunder, Express, Whirlwind link address: Actual address: $url;?>” target=”_blank”><?php echo $url;?> Thunder chain: $url_thunder;?>” target=”_blank”><?php echo $url_thunder;?> Express chain: $url_flashget;?>” target=”_blank”><?php echo $url_flashget;?> Whirlwind chain: $url_qqdl;?>” target=”_blank”><?php echo $url_qqdl;?> The code in PHP to generate the Thunder Express whirlwind link from the address

In php, date() outputs 12-hour clock and 24-hour clock to distinguish

php date() method to output 24-hour time: 1 echo date ( “Y-m-d H:i:s” ); How to output 12-hour time: 1 echo date ( “Y-m-d h:i:s” ); The difference between the two methods lies in the difference in upper and lower case, just change the letter. Uppercase Y indicates the complete year, such as: 2014, while lowercase y indicates the year Shorthand, for example: 14 Uppercase H means 24-hour clock, while lowercase h outputs the time in 12-hour clock . The code below: 1 2 3 echo date ( “Y-m-d H:i:s” ). ““; echo date ( “y-m-d h:i:s” );  The output to the browser is: 1 2 3 2014 – 03 – 01 14: 09: 15 14 – 03 – 01 02: 09: 15

In PHP, I want to use regular expressions to get the four array elements of the array (@中肖, @角, @地s_3法, @在有) that do not contain @ spaces.

$str = ‘@中肖@秘静@地s_3法@在有@’; preg_match_all(‘/@+\s/’, $str, $matchs); I want to get xxx between @ and space (can be Chinese and English, underscore and other symbols) I wrote this wrong. Ask heroes for help. Thank you! Of course, there are other ways to get the array (@中晓,@角,@地s_3法, @在有) also works, please enlighten me! 4 solutions #1 $str = ‘@中肖@秘静@地s_3法@在有@’; preg_match_all(“/@\S{1,}\s/”, $str, $matchs); \S (uppercase) means all non-whitespace characters, followed by {1,} means there must be at least one matching byte #2 I was careless, there is no need to follow \S with a \s, it will be superfluous #3 [[email protected] php_project]$ php main.php Array( [0] => @中肖 [1] => @角 [2] => @地s_3法 [3] => @在有 )[[email protected] .baidu.com php_project]$ cat main.php <?php$content = “@中肖 @秘静@地s_3法 @在有@ “;$n_match = preg_match_all(‘/ @.* /U’, $content, $matches);if ($n_match) { $res = array_filter($matches[0], function($item){return trim($item, ” @ “);}); print_r($res);}?> #4 $str = “@中肖@秘静@地s_3法@在有@”; preg_match_all(‘/@\S{1,}/’, $str, $matchs); for ($i = 0; $i < count($match[0]); $i++) { echo “[“.$i.”] => “.$matchs[0][$i].”“; } thanks to the help of the two upstairs! qq120848369 $res = array_filter($matches[0], function($item){return trim($item, “@ “);}); An error occurred while running this sentence. Thank you dream1206 for your answer and analysis!

In PHP, what does if (\false) (yes, use a backslash) mean?

This morning, I received a notification of a new Twig_Extensions version! Great! I’d like to see changes before integrating it into the twigfiddle. This is basically adding support for namespaces using the class_alias function, and then adding the PSR-4 counterpart classes that only include older versions. But every new (namespaced) class is implemented like this: <?php namespace Twig\Extensions; require __DIR__.'/../lib/Twig/Extensions/Extension/Text.php'; if (\false) { class TextExtension extends \Twig_Extensions_Extension_Text { } } What does this symbol mean? 1> Dale..: This means it uses false as defined in the global namespace. After some research, the rest of this answer is nonsense… I swear, you could do this with PHP at one point in time. I think this is to bypass the situation I’ve never seen any code, but this is what comes to mind.

In PHP, is it more efficient to use lambda expressions for callables instead of strings (or arrays)?

In PHP, some functions take a “callable” as an argument, which means you can specify a function to be executed at a certain point. An example is array_map. PHP allows you to specify callable objects in various ways, for example: // as a string: $lowerCaseStrings = array_map(‘strtolower’, $arrayOfStrings); // object methods as an array // (this could be done with DateTime directly, of course): class DateFactory { private $format; public function __construct($format) { $this->format = $format; } public function newDate($dateString) { return DateTime::createFromFormat($this->format, $dateString); } } $factory = new DateFactory(‘Y-m-d’); $dates = array_map(array($factory, ‘newDate’), $arrayOfDateStrings); // as a lambda expression / closure: $dates = array_map( function ($dateString) { return DateTime::createFromFormat(‘Y-m-d’, $dateString); }, $arrayOfDateStrings ); Now, I think the latter form is evaluated once by the PHP engine during compile time, while the other form may be evaluated during runtime, possibly for each call, which means using closures for a large number of calls would be more efficient. Is this assumption correct?

In php, the value of an array is key and the value of another array is a value to form an array

array_combine($array1,$array2); The value of $array1 is the key and the value of $array2 is the value to form a new array

In PHP, how to generate a large pseudorandom number? -InPHP, how do I generate abig pseudo-random number?

I’m looking for a way to generate a big random number with PHP, something like: I’m looking for a way to generate a large random number in PHP, eg: mt_rand($lower, $upper); The closer I’ve seen is gmp_random() however it doesn’t allow me to specify the lower and upper boundaries only the number of bits per limb (which I’ve no idea what it is). I’ve looked closer to gmp_random() but it doesn’t allow me to specify the lower and upper bounds only the number of bits per limb (I don’t know about it what is). EDIT: Axsuuls answer seems to be pretty close to what I want and very similar to gmp_random however there seems to be only one flaw in one scenario. Edit: Axsuul’s answer seems to be very close to what I want, very similar to gmp_random, but seems to have only one flaw in one scenario. Suppose I wan’t to get a random number between: Assuming I don’t want to get a random number in between: 1225468798745475454898787465154 and: 1225468798745475454898787465200 So if the function is called BigRandomNumber(): So, if the function name is BigRandomNumber(): BigRandomNumber($length = 31); This can easily return 9999999999999999999999999999999 which is out of the specified boundary.…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索