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.
Related
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.
This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
PHP String Concatenation With Variables [duplicate]
(1 answer)
Concatenating strings retrieved from form $_Post in php
(1 answer)
php String Concatenation, Performance
(12 answers)
Concatenate HTML string and variable in PHP [closed]
(3 answers)
Closed 2 years ago.
I was wondering if you can add a variable to a file-path.
Example:
path: C:\\users\\john\\school\\hardware.properties";
I want to make a variable of the word preceding the . (dot) - in this case, "hardware" - so the user can write a name in a form and search/get another property.
You can just make it a string and add the var into it
$name = $_POST['name']
$path = "C:/.../".$name.".properties"
I just make more sure what Jasper B want to write:
In your form you have some submit input and text input.
You will get datas from inputs so you will just access them like:
$name = $_POST["name"];
After you just put $name variable to path like:
$path = "C:\users\john\school\".$name.".properties";
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 4 years ago.
I would like to assign a variable into the PHP code, which will change my URL. For example
$page = 'http://www.example.com/search-products?type=buildings&q=small&go=Go';
Where q=small i would like to change to say q=big (using a variable)
I have assigned a variable within PHP but i am unable to get it to work?
for example
$q= 'big';
$page = 'http://www.example.com/search-products?type=buildings&q=$q&go=Go';
The url does not however update - Any help would be appreciated
Use strings with " and not with ' if you're using variables in it.
$page = "http://www.example.com/search-products?type=buildings&q={$parameter}&go=Go";
Check this :
$page = "http://www.example.com/search-products?type=buildings&q={$q}&go=Go";
Note: Single quotes don't work in this case.
If you use Single quotes, you see something like this :
echo 'q={$q}';
//Output => q={$q}
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";
This question already has answers here:
How do I convert a string to a number in PHP?
(35 answers)
Closed 7 years ago.
So lets show an example here shall we?
Let's say I have 2 strings that are like this....
$math1 = "+300";
$math2 = "-125";
So obviously the answer would have to be +175 but how do I actually do the math while the input is a string.
I can't simply do
$math1 - $math2
Because it'd have to figure out if it is a + or a -, so how can this exactly be done?
You can use intval to get the integer value of a variable, and then you can do basic math operations.
<?php
$math1 = intval("+300");
$math2 = intval("-125");
echo $math1 - $math2;
?>
intval($math1) + intval($math2);
Can be:
$result = abs($math1) - abs($math2);