Getting A non-numeric value when combining strings PHP [duplicate] - php

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 2 years ago.
I have this code:
echo "<p>" + $username + "<\/p>"
and $username is a string. I get this error:
Warning: A non-numeric value encountered
I don't know why i get this. How can i fix this?

Use "." instead of "+" to concat strings, "+" is only for Arithmetics.

Related

How to concatenate string with having single ,double quaotes or special characters in php? [duplicate]

This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Send PHP variable to JavaScript function [duplicate]
(6 answers)
How to pass php variable to JavaScript function as parameter
(4 answers)
how to pass php variable to javascript?
(2 answers)
Closed 12 months ago.
I am having one onclick event with some paramters with it. But in some
cases i am getting double quaotes or space between strings. so getting
error of Uncaught SyntaxError: missing ) after argument list or
invalid token.
How to overcome with this issue. I tried to use array and trim the
variables but it wont work for me.
$stringArray = ['string 1', 'string'2','001'];
$concatenated = trim(implode(',',$stringArray));
E.g: I am getting 3 string like :
$data1 = 'surgery';
$data2 = 'Cardio'c';
$data3 = 'hopsital ab"cc';
<a id='changeState' onclick=editModal(\"". $data1 ."\",\"". $data2 ."\",\"".$data3."\");>Click Here</a>
Please help to resolve this issue.

Best way to convert string[which is basically a comma seprated number] to an integer in PHP [duplicate]

This question already has answers here:
How do I convert a string to a number in PHP?
(35 answers)
Closed 2 years ago.
I have a value like 12,25,246
I want to get 1225246 (must be an integer)
How can I do that?
I have searched a lot but there are direct answer like converting string to integer but not like this actually these both are like integer
I have tried php formate_number but it did not worked.
You could use a combination of intval() and str_replace() to do this.
Example:
$value = '12,25,246';
var_dump(intval(str_replace(',','',$value)));
// Yields: "int(1225246)"
Sandbox
$number = (int)str_replace(',', '', '12,25,246');
here is it

pluses are getting stripped from GET variable in php [duplicate]

This question already has answers here:
PHP - Plus sign with GET query
(6 answers)
When should space be encoded to plus (+) or %20? [duplicate]
(5 answers)
Closed 3 years ago.
First of all thanks in advance to everyone helping me out with my question.
I've got a base64_encoded string that looks like:
$_GET['val']='8AH1Oc+gqwjMPyyAL+PIu2neFF5C+bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd+7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX+I+qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy+K9ABLBqUta9+0Mk3JCg+wO/WA2Bh06M0n4ux+qk=';
but when im trying to get the same variable to decode it i recieve it with pluses removed:
$string=$_GET['val'];
echo $string; // either echo $_GET['val']; output will be '8AH1Oc gqwjMPyyAL PIu2neFF5C bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd 7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX I qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy K9ABLBqUta9 0Mk3JCg wO/WA2Bh06M0n4ux qk='
Could somebody please explain why does it happen?

Escaping quotes PHP echo [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 5 years ago.
I'm having some weird problem escaping " in an echo function.
echo "Site";
Any idea what I'm doing wrong?
You are doing it the javascript way for one. Concatenating in PHP works using . or ,.
Then you are using to many "
Try this line:
echo "Site";

Array of string php [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 8 years ago.
I'm tring to create an array of string but I can't do this if I use a variable.
$dir_photo="./Foto_NEW/";
$photo= array($dir_photo+"DSCN2507.JPG",$dir_photo+"IMG_0054.JPG",$dir_photo+"IMG_0058.JPG");
The result is 0 0 0.
+ is the concatenation operator in Javascript, but in PHP it's the period . So what you need is this:
$photo= array($dir_photo."DSCN2507.JPG",$dir_photo."IMG_0054.JPG",$dir_photo."IMG_0058.JPG");
You need to replace the + with a .
$dir_photo."DSCN2507.JPG"
+ is used in javascript, . is used in php
Try this:
$dir_photo="./Foto_NEW/";
$photo= array($dir_photo."DSCN2507.JPG",$dir_photo."IMG_0054.JPG",$dir_photo."IMG_0058.JPG");
You need to use . instead of + to concatenate strings.

Categories