str-replace

Regex str_replace

限于喜欢 提交于 2019-12-18 05:40:33
问题 Would it be possible to incorporate a str_replace method with a regular expression, designed to catch url strings in a simple html < textfield > input type? I'm considering something simple like a tip for the user to set it up as follows: This is some text and click this link here. Obviously the word "here" is a href to the url before it (or after it, if that makes a difference). The text input is drawn from a MySQL db. I believe the start of my solution is something along the lines of:

PHP: “… variables can be passed by reference” in str_replace()?

不问归期 提交于 2019-12-18 04:30:23
问题 I created a function to print a prepared-statement-sql-string with the variables in it, based on what I found in this other StackOverflow question. Here is my code: foreach($params as $idx => $param) { if ($idx == 0) continue; $sql = str_replace('?', "'" . $param . "'", $sql, 1); } printError($sql); When I run this I get: Fatal error: Only variables can be passed by reference for line 3. However when i use $sql = preg_replace('/\?/', "'" . $param . "'", $sql, 1); for line 3 it works fine. Any

Can't get str_replace() to strip out spaces in a PHP string

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 02:46:36
问题 Hi, I am getting a PHP string which I need to strip the spaces out of. I have used the following code but when I echo $classname it just displays the string still with the spaces in it. <?php $fieldname = the_sub_field('venue_title'); $classname = str_replace(' ', '', $fieldname); echo $classname; ?> 回答1: Try to add u -parameter for regex-pattern, because a string can have UTF-8 encoding: $classname = preg_replace('/\s+/u', '', $fieldname); 回答2: If you know the white space is only due to

ASP.net c# replace string not working

耗尽温柔 提交于 2019-12-17 21:14:37
问题 // Build email link confirmLink = Master.siteDomain + "/newsLetter.aspx?action=confirm&e=" + emailAddress + "&code=" + verCode; using (SqlCommand cmd = new SqlCommand("SELECT newRegEmailBody, newRegEmailSubj FROM tblSiteSettings WHERE (isActive = 1)", Master.cn)) { SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { emailBody = rdr[0].ToString(); emailSubj = rdr[1].ToString(); } rdr.Close(); } emailBody.Replace("[CONFIRMATION_LINK]", confirmLink); emailer.sendEmail(emailAddress, Master

replace string in an array with php

泪湿孤枕 提交于 2019-12-17 18:55:50
问题 How can I replace a sub string with some other string for all items of an array in php? I don't want to use a loop to do it. Is there a predefined function in php that does exactly that? Edited: Thank you for your reply,one more question,how can i do that on keys of array? 回答1: $array = array_map( function($str) { return str_replace('foo', 'bar', $str); }, $array ); But array_map is just a hidden loop. Why not use a real one? foreach ($array as &$str) { $str = str_replace('foo', 'bar', $str);

str_replace with array

不打扰是莪最后的温柔 提交于 2019-12-17 16:44:10
问题 I'm having some troubles with the PHP function str_replace when using arrays. I have this message: $message = strtolower("L rzzo rwldd ty esp mtdsza'd szdepw ty esp opgtw'd dple"); And I am trying to use str_replace like this: $new_message = str_replace( array('l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k'), array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'), $message); The

Reformat string containing date with Javascript

我是研究僧i 提交于 2019-12-17 06:56:49
问题 I have the following string which I ultimately need to have in the format of mm/yy var expDate = 2016-03; var formatExp = expDate.replace(/-/g , "/"); This gets me to 2016/03, but how can i get to 03/16? 回答1: one solution without regex: var expDate = '2016-03'; var formatExp = expDate.split('-').reverse().join('/'); //result is 03/2016 alert('result: ' + formatExp); var formatExpShort = expDate.substring(2).split('-').reverse().join('/'); //result is 03/16 alert('result short: ' +

Str_replace for multiple items

感情迁移 提交于 2019-12-17 04:47:46
问题 I remember doing this before, but can't find the code. I use str_replace to replace one character like this: str_replace(':', ' ', $string); but I want to replace all the following characters \/:*?"<>| , without doing a str_replace for each. 回答1: str_replace() can take an array, so you could do: $new_str = str_replace(str_split('\\/:*?"<>|'), ' ', $string); Alternatively you could use preg_replace(): $new_str = preg_replace('~[\\\\/:*?"<>|]~', ' ', $string); 回答2: Like this: str_replace(array(

Str_replace for multiple items

怎甘沉沦 提交于 2019-12-17 04:47:40
问题 I remember doing this before, but can't find the code. I use str_replace to replace one character like this: str_replace(':', ' ', $string); but I want to replace all the following characters \/:*?"<>| , without doing a str_replace for each. 回答1: str_replace() can take an array, so you could do: $new_str = str_replace(str_split('\\/:*?"<>|'), ' ', $string); Alternatively you could use preg_replace(): $new_str = preg_replace('~[\\\\/:*?"<>|]~', ' ', $string); 回答2: Like this: str_replace(array(

PHP template class with variables?

人盡茶涼 提交于 2019-12-14 03:39:42
问题 I want to make developing on my new projects easier, and I wanted a bare bones very simple template engine solution. I looked around on the net and everything is either too bloated, or makes me cringe. My HTML files will be like so: <html> <head> <title>{PAGE_TITLE}</title> </head> <body> <h1>{PAGE_HEADER}</h1> <p>Some random content that is likely not to be parsed with PHP.</p> </body> </html> Obviously, I want to replace {PAGE_TITLE} and {PAGE_HEADER} with something I set with PHP. Like