Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Please tell me how to do a find and replace in PHP.
I nee to find Entry="OK" and replace with OK in a xml file.
I tried str_replace but confused because of the = and " in it.
Even though I'm not sure of the environment you're working in, here's a php sample that I think does what you want:
<html>
<?php
$teststr = "Entry=\"OK\"";
print $teststr . "<br>";
$newanswer = str_replace($teststr, "Entry=OK", $teststr);
print $newanswer . "<br>";
?>
</html>
Try this way
str_replace('Entry="OK"','OK',$var);
You can use str_replace its working
$r = 'Entry="OK" tyyuu hhh';
echo str_replace($r,'Entry="OK"','OK');
if any error found then u use preg_replace with corresponding patteren
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to create a unique id by concatenating 3 variables using forward slashes(/). my code is like so
$year . "/" . $acronym . "/" . $num;
I am expecting an output of
"18/MC/1"
but the output I get is
"18\/MC\/1"
What am I doing wrong. I have already tried using stripslashes() but it doesn't do anything to the output.
You could use join function
<?php
// ...
join([$year, $acronym, $num], '/');
For more info, see: Join function documentation
I found what was wrong,
The code below outputs the correct format 18/MC/1
return response()->json([$id]);
while my previous code was
return response()->json($id);
which gave me an output of
`"18/MC/1"
There is function in php to remove backward slash from string use following function.
echo stripslashes(string);
output: 18/MC/1
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My value is coming like this with two enters. please see below :
125
124
132
I am getting this value by php variable and want to get values with commas in new php variable.
i want like this 125,124,132
anyone have an idea for that please?
$str = "125
124
132";
$str = str_replace("\r\n\r\n", ",", $str);
echo $str;
Try the above code. Please let know if this worked.
You can directly add commas between numbers using
number_format() function of PHP
<?php
echo number_format("125124132")."<br>";
?>
Answer:- 125,124,132
Try the above given code and let me know if this worked.....
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
function wrap($str) {
$str="[#id=\"".$str."\"]";
return($str);
}
$str="Hi";
$str=wrap($str);
I would have $str like [#id="Hi"], but i have $str like [#id=\"Hi\"]
How could i do that?
$str='[#id="'.$str.'"]';
replace " with '
The code works as expected, no need to change quotes to single ticks or remove the second pair of double quotes.
Probably the backslashes are added later. If you just echo $str; after your snippet it shows this in a browser
[#id="Hi"]
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Im newbie in php im learning it since some weeks ago but i didnt understand one thing.
I have a
$url = "http://example.com/";
define('LOCATION', '<?php echo $url; ?>');
but it is not working. I didnt understand why "define" term cannot read
<?php
$url = "http://example.com/";
define('LOCATION', $url);
1.You are alreay in php tag,so no need of any extra php tag.
2.And when assigning value to a variable , we never use echo in php . Its used to display value in html only.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a variable inside an inline style -
style='color:$custom_color;font-size:$custom_icon_size;'
And am trying to add the letters px directly after the $custom_icon_size. This obviously does not work? Any ideas what is the correct method?
thanks
you need to use {} around your PHP vaariable
style='color:$custom_color;font-size:${custom_icon_size}px;'
Assuming that you're echoing it, you have two options:
echo "style='color:$custom_color;font-size:{$custom_icon_size}px;'";
echo "style='color:" . $custom_color . ";font-size:" . $custom_icon_size . "px;'";
$style = 'color:'.$custom_color.'; font-size: '.$custom_icon_size.'px';
echo 'style="'.$style.'"';