str-replace

Template class not looping with str_replace

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:59:41
问题 Well i have this set of codes <?php include "includes/config.php"; class template{ var $page; var $built; public $block = array(); function _start($tpl){ $this->page = $tpl; } function set_array($data){ $this->block[] = $data; } function _show(){ foreach($this->block as $k => $v){ foreach($v as $k1 => $v1){ //echo $k1."<br />"; //echo $v1."<br />"; $this->page = str_replace("{".$k1."}", $v1, $this->page); } } echo $this->page; } } $template = new template(); $file = "<html> <body> <p>{CAT}</p

Php str_replace - two values to replace?

ぃ、小莉子 提交于 2019-12-12 01:49:41
问题 Using str_replace I want to change $url from this: $url = http://example.com/images/lala1.jpg to this $url = http://example.com/images/lala1-0001.jpg My problem is that I don't know how to insert the "-". $url is changing so I really only know that it has ".jpg" at its' end. My code so far: for($i=1;$i<=9;$i++) { $array[] = str_replace('.jpg',sprintf("%04d",$i).'.jpg',$url); } Any idea how I can make this work? 回答1: Sprintf allows for regular characters in the arguments: str_replace('.jpg',

str_replace does not work for some cases

怎甘沉沦 提交于 2019-12-12 01:34:23
问题 I use curl to get html and save it to $content. Then I try the str_replace, it doesn't work: echo str_replace('<a onclick="get_content(\'http://en.wikipedia.org\');" style="cursor: default;">Dojo</a> Applications','OK',$content); But when I try to print $content and copy the source and save it to $content again, it works: echo $content; Then I copy the printed and save it to $content again: $content='It is <a onclick="get_content(\'http://en.wikipedia.org\');" style="cursor: default;">Dojo</a

php str_replace hex color

喜夏-厌秋 提交于 2019-12-12 01:33:52
问题 how do you replace this string *#ff00ff Hello World *000000 to <span style='color:#ff00ff'> Hello World </span> using str_replace? Thanks. 回答1: $string = '*#ff00ff Hello World *000000'; $string = preg_replace('/\*#([a-f\d]{6})(.*)\*[a-f\d]+/', "<span style='color:$1'>$2</span>", $string); echo $string; can also be done like so: $string = '*#ff00ff Hello World *000000'; $string = preg_replace('/\*#([[:xdigit:]]{6})(.*)\*[[:xdigit:]]+/', "<span style='color:$1'>$2</span>", $string); echo

replace string on condition - php

拟墨画扇 提交于 2019-12-12 00:49:01
问题 i am facing an issue here , trying to replace string with another under a condition. check the example : $data = ' tony is playing with toys. tony is playing with "those toys that are not his" '; so i want to replace toys with cards . but only which is NOT in ques ( " ). i know how to replace all words that are toys . $data = str_replace("toys", "cards",$data); but i don't know how to add a condition which specifies to replace only the one's which are not in the ( " ). can anyone help please

Using a string as an expression to be send to eval() and replacing a sub-string with a vriable value PHP

不羁的心 提交于 2019-12-12 00:30:05
问题 I need some help with basic syntax in PHP, I got the following string : $str = "return (strlen(replace) <= 5 && strlen(replace) >= 1);"; and I got a variable : $var = "VariableValue"; and the st_replace function as : str_replace('replace', $var, $str); What I am trying to do is actually use eval in somehing like: if(eval($str)){//This should now make the if condition **look like** //if(strlen(*'VariableValue'*)...) // echo 'Success'; }else{ echo 'Ask the guys at StackOverFlow :),sure after

php preg_replace € sign with “euro”

拟墨画扇 提交于 2019-12-11 20:39:43
问题 I would like to replace the € sign in $XML_COMMENT with "euros" before adding to a xml file. The € sign not being a utf-8 character I get and error message from simplexml Warning: SimpleXMLElement::addAttribute(): string is not in UTF-8 in ... Warning: SimpleXMLElement::asXML(): output conversion failed due to conv error, bytes 0x82 0x26 0x61 0x6D in .... The euro sign appears in the MySQL (utf-8) database as '€' But appears correctly in the textarea on the webpage. I tried to use these

STR_Replace Issues With Soap Envelope

懵懂的女人 提交于 2019-12-11 17:53:04
问题 I am trying to use the str_replace() function to remove the S:Envelope and S:Body tags from my Soap XML output. Despite many attempts I have been unable to remove these tags. I need to remove the tags so that I can pull data from the XML output using logic such as echo $xml->vinDescription->WorldManufacturerIdentifier . "<br>"; With the Soap tags present, I am unable to do this. Here is my XML output (note.xml): <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body>

Replacing keywords in text with php & mysql

本小妞迷上赌 提交于 2019-12-11 15:45:09
问题 I have a news site containing an archive with more than 1 million news. I created a word definitions database with about 3000 entries, consisting of word-definition pairs. What I want to do is adding a definition next to every occurence of these words in the news. I cant make a static change as I can add a new keyword everyday, so i can make it realtime or cached. The question is, a str_replace or a preg_replace would be very slow for searching 3 thousand keywords in a text and replacing them

Formatting phone number in XSLT

佐手、 提交于 2019-12-11 15:38:13
问题 I am having a phone number in my xml in this format like (515) 123456 and I need to have it like simple like 515123456. I used below code and it's throwing me an error any idea how this can be done ? <xsl:value-of select="replace(replace(Mobile1, ') ', ''), '(', '')" /> 回答1: The second argument of the replace() function is a regex pattern. Parentheses are special characters in regex, and must be escaped when used literally: <xsl:value-of select="replace(replace(Mobile1, '\) ', ''), '\(', '')"