problem about str-replace-Collection of common programming errors
user1860536
php function preg-replace str-replace
I try change characters by functions<?php $string = “Hi everybody people [gal~images/articles~100~100~4] here other imagen [gal~images/products~100~100~3]”;$regex = “/\[(.*?)\]/”; preg_match_all($regex, $string, $matches);for($i=0; $i<count($matches[1]);$i++) { $match = $matches[1][$i]; $array = explode(‘~’, $match);//$newValuet=”gal(“”.$array[1].””,””.$array[2].””,””.$array[3].””,””.$array[4].””)”;$newValue=”gal(“.$array[1].”,”.$array[2].”,”.$array[3].”,”.$array[4].”)”;$string = str_repl
Clay Smith
php str-replace
I am getting an error on the str_replace line. I am trying to replace the $_SESSION variable with the constant of it. What am i missing?$resume = fopen(‘creative/’.$_SESSION[‘user’].’/resume.php’, ‘r’) or die(‘error when opening the file’); $fp = fopen(‘creative/’.$_SESSION[‘user’].’/resume2.php’, ‘w’); $creative = $_SESSION[‘creative’]; $user = $_SESSION[‘user’]; if ($resume){ while (($buffer = fgets($resume, 4096)) !== false) {str_replace(“\$_SESSION[creative]”, $creative, $buffer);str_replace
user3185672
javascript php xmlhttprequest youtube-api str-replace
I have this PHP code, which try to get the description of a YouTube channel, and run it in a JS file (xhr_object), and I’ve got this error : Unexpected token ILLEGAL. But I found the problem : $channel_descr contains a simple quote in somes cases, which break the JS code. I’ve already tried to use str_replace() but it doesn’t change anything..$json = file_get_contents(“…?alt=json&part=snippet”); $data = json_decode($json, true);$channel_descr = $data[‘entry’][‘content’][‘$t’]; $channel_des
sparkle
php str-replace
String (JSON): {“title”:”\”Copper\””}I have tried$output = str_replace(‘\\”‘, “”, $output);but I got{“title”:”” Copper””}What I expect{“title”:”Copper”}
DevatoTech
php str-replace
$embedCode = <<<EOF getApplicationContent(‘video’,’player’,array(‘id’ => $iFileId, ‘user’ => $this->iViewer, ‘password’ => clear_xss($_COOKIE[‘memberPassword’])),true) EOF; $name = str_replace($embedCode,”test”,$content);I’m trying to replace a section of code with another piece of code. I can do it with smaller strings but once I added the larger strings to $embedCode, it throw an “unexpected T_ENCAPSED_AND_WHITESPACE” error
binki
php arrays str-replace
php > echo str_replace(array(‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’),array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’),’01234567890abcdef’) . PHP_EOL; klmnopghijkklmnopI expected this str_replace() call to give me something like abcdefghijklmnop. But it seems that the numeric strings in my search array are being treated as something other than strings.I am ultimately just going for the functionality of tr(1) (e.g., tr
Isaac Boda
php str-replace
<?php $date = date(‘n/j/Y’); $lines = file(‘../lines.txt’);foreach($lines as $line)$line = str_replace($date, ”, $line);echo $line; ?>Why will the above str_replace work for me, no matter how I re-arrange it I get this error:Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in File line 20 ($line = str_replace ….)
HamZa
php str-replace
I have to alter two things in this example text:example_1,example_2I need to appear this way: example 1, example 2So I need to replace the “_” with a space ” ” as well as the “,” to “, ” with a space. Currently I have this code below and it replaces the underscore fine, but I don’t know how to also integrate the “,” part in this code. str_replace(‘_’, ‘ ‘, $test)Would it be something like this:str_replace((‘_’, ‘ ‘,),(‘,’, ‘ ‘), $test)
joelrnorris
php syntax str-replace autoloader psr-0
I’m dabbling w/ a ‘lightweight’ PSR-0 AutoLoader for a WordPress Plugin, it runs fine on my local dev server, but when i push it up to one of WPEngine’s staging servers, i get this:Parse error: syntax error, unexpected ‘[‘, expecting ‘)’ in /nas/wp/www/staging/ahsodesigns/wp-content/plugins/AhSoFunctionality/start.php on line 30here’s the AutoLoader, // lightweight psr-0 autoloader spl_autoload_register(function ($classname) {// make sure we’re only loading classes from our directory,if (preg_m
Fuxi
php str-replace
i’m having the following php code:$html = ‘<p>[tag]</p>’;$test = “<a href=’#’><div class=’test’>button</div></a>”;$html = str_replace(“[tag]”, $test, $html);when using echo htmlentities($html) i’m getting the expected result:<p><a href=’#’><div class=’test’>button</div></a></p> but when echoing the $html, firefox renders it like this:<p> <a href=”#”></a> </p> <div class=”test”> <p></p&g
Homunculus Reticulli
php str-replace
I am writing a trivial templating system for running dynamic queries on a server.I originally had the following code in my templating class:$output = file_get_contents($this->file);foreach ($this->values as $key => $value) {$tagToReplace = “{$key}”;$output = str_replace($tagToReplace, $value, $output); }I notice that the strings were not being replaced as I expected (the ‘{}’ characters were still left in the output) .I then changed the ‘offending’ line to:$tagToReplace = ‘{‘.”$key”.’}’
lserni
php arrays str-replace
I’ve the following function and using str_replace gives an unexpected resultfunction repo($text) {$search = array(“0″,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9”);$replace = array(“z30″,”z31″,”z32″,”z33″,”z34″,”z35″,”z36″,”z37″,”z38″,”z99”);$text = str_replace($search,$replace,$text);return $text; }echo repo(‘0’);The expected answer isz30and instead I getzz330What am I doing wrong?
Christian
php str-replace
I am working on a file that should replace a variable in another file. So far I tried:$File = “$dir/submit.php”; $fh = fopen($File, ‘r’) or die(“Couldn’t edit the Config-file. Please report to admin.”); $chosendb = str_replace(‘$chosendb = comments;’,’$chosendb = wuhuws_$dir;’,’$chosendb’); fclose($fh);$dir is a user input. comments is a table in the database that need to replaced with the prefix_$dir.What do I do wrong?
Karoumpas
php str-replace
This gives me error$illegal = array(“&”, “<“, “>”, “\”); $legal = array(“&”, “<”, “>”, “"”);$row[‘name’] = str_replace($illegal, $legal, $row[‘name’]);this is the main part of the code$xml_output = “<?xml version=\”1.0\”?>\n”; $xml_output .= “<products>\n”;for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){$row = mysql_fetch_assoc($resultID);$xml_output .= “\t<product>\n”;$xml_output .= “\t\t<id>” . $row[‘id’] . “</id>\n”
sea_1987
php regex preg-replace str-replace ereg
I have a php system that uploads images and suffixes their files names with -med -slider etc dependant on what size the image is. However only one of the image filenames get saved to the database, so when I want to display an image and call the filename from the database, I get something like, filename-med.jpg how can I change that so I can replace -med with -slider? is this possible? I am no good at regex and I assume I would have to use that?
Daniel
php str-replace htmlspecialchars
I have this code to get the HTML source of a website/file and replace some parts of its content. Later I print the modified result <?php // Get a file into an array. In this example we’ll go through HTTP to get // the HTML source of a URL. $lines = file($link);// Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) {} ?> <?php $old = array(“document.write(“, “‘”, “)”, “<a href="”, “</a>
yckart
jquery regex replace template-engine str-replace
I’ve written some days ago a simple templating function, problem now is that whitespace will kill the tag. So when I type something like this: <div id=”str”>#{my} #{name} #{is} #{#{a}}</div> it works well, however the following does not: <div id=”str”>#{my} #{name} #{is} #{ #{a} }</div>.Here’s what I’ve done so far:$.tmpl = function(str, obj) {do {var beforeReplace = str;for(var key in obj) {str = str.replace(“#{” + key + “}”, obj[key]);}var afterReplace = str !== beforeR
user841852
string matlab str-replace numerical equation-solving
Hello I am new to MATLAB , I wanted to know how can I make my string into function . I want to access the function as a string from user in standard Matlab format (e.g exp(-10*X)-sin(pi*X)-2*tanh(X) ) Here X is the variable. Then I want to replace ‘X’ with ‘low’ and ‘high’ variables to calculate value of function at these limits. I have used ‘strrep’ for this purpose. I am getting the following errors 1)Undefined function or variable ‘X’. 2) I cannot see whether ‘X’ was replaced with ‘low’ and ‘
alladeen
php templates str-replace
I have one array for data$data = array(title=>’some title’, date=>1350498600, story=>’Some story’);I have a template$template = “#title#, <br>#date(d)#<br> #date(m)#<br>#date(Y)#<br> #story#”; All i want is to fit data into template and i know that can be done by str_replace but my problem is the date format. date format is coming from the template not from the data, in data date is stored as php date. yesterday i tried to ask the same question but i think my que
Gabriel Meono
php str-replace
I’m working with a CMS spanish website, and I’m trying to replace the months to spanish.This is how it looks like with the date function date(“F j, Y, g:i a”):August 24, 2011, 1:47 pmNow I want it to look like this:Agosto 24, 2011, 1:47 pmUsing an example from the Php Documentation I made this:$p[‘time’] = date(“F j, Y, g:i a”);$time_english = $p[‘time’];$search = $time_english(‘August’, ‘September’, ‘October’, ‘November’, ‘December’);$replace = $times_spanish(‘Agosto’, ‘Septiembre’, ‘Octubre’,
user1566521
arrays fopen str-replace explode
I am having trouble understanding this. I’ve read many other posts here and elsewhere but I just don’t get it. I think maybe because I have a hard time visualizing other’s examples. Could someone please give me some insight as to what I am doing wrong here.1. $data = file_get_contents(“rawtext.txt”); 2. 3. $kList[0] = “uszips.txt”; 4. $kList[1] = “cities.txt”; 5. $kList[2] = “states.txt”; 6. 7. foreach($kList as $replacelist) 8. { 9. 10. 11. $fp = @fopen($kList, ‘r’); 12. if ($fp) { 13.
casperOne
php asp-classic replace str-replace
Hi I want to do a simple replace using str_replace, like Classic ASP.$strName=”Blush / Black”; $strName=$strName(str_replace(“/”,”&”));It should read, when echo:Blush & Black. I get an Fatal error: Call to undefined function
Web site is in building