This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 9 years ago.
I need to switch on E_ALL and get the in the title mentioned warning, when I am exploding the $_GET string:
$input = explode( '/', $_GET['string'] );
Where does that come from? Is it the missing 3rd parameter (limit) for explode ? I want all entries.
Cheers
You need to make use of the isset construct first.
<?php
if (isset($_GET['string'])) {
$input = explode('/', $_GET['string']);
} else {
echo "The string was not passed!";
}
Related
This question already has answers here:
Check if variable starts with 'http'
(6 answers)
Closed 3 years ago.
I have a variable and i want to check if it starts with 'pa_' how can I do that?
i have tried this but it does not work
$test_str = 'pa_';
if(substr( $product_attribute['name'], 0, strlen($test_str) ) === $test_str) {
$pa_array[]= $product_attribute['name'];
}
Just check if pa_ is at the first position of the string
if (strpos($product_attribute['name'], 'pa_') === 0) {
$pa_array[]= $product_attribute['name'];
}
Try dd($pa_array) within the if-block to see if you even put it in the array.
I quickly tried this and it worked.
Use strpos or access chars in a string by using an offset value:
$paName = $product_attribute['name'];
if($paName[0] . $paName[1] . $paName[2] == $test_str) {
$pa_array[]= $paName;
}
This question already has answers here:
What does it mean to escape a string?
(3 answers)
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 5 years ago.
I want to output a string like this "{$myvar}" but it doesn't work.
if for example $var = 1;
echo "$var"; // output "1"
echo "{$var}"; // output "1"
echo "\{$var\}"; // output "\{1\}"
how do I get "{1}" as a result ???
thanks
This question already has answers here:
How to check if a string starts with a specified string? [duplicate]
(5 answers)
Closed 8 years ago.
I was looking and found How to check if variables starts with specific string & How to chech if a variable contains specific string but, I don't get it.
Which one could I use to check if a variable STARTS with a specific string just like a MYSQL LIKE WHERE CLAUSE:
SELECT * FROM table WHERE column LIKE 'string%'
You could use this, to match for any length string. Instead of hardcoding the string and it's length.
$string = "string to test";
$testfor = "strin";
if(substr( $string, 0, strlen($testfor) ) === $teststr) {
echo "Match";
}
if(substr($string, 0, 5) === "String") {
# Do code
} else {
# Error
}
Easy enough for simple strings.
This question already has answers here:
PHP - if condition inside string
(5 answers)
Closed 8 years ago.
I have a string like this:
$str = "0 || 0 && 1";
actually this string is a condition.
if i do like this :
if($str) {
echo "done";
}
else {
echo "sfcsd";
}
it is always true since $str is string.
How can i evaluate this string with out eval().
check out sandboxing in PHP. here is a quick tutorial:
http://www.fieryprophet.com/blog/detail/sandboxing-untrusted-code-with-phpsandbox
This question already has answers here:
Using braces with dynamic variable names in PHP
(9 answers)
Closed 8 years ago.
What I mean is can I do something like this...
$number = 1;
$varname = 'number';
Now I want to get the value of $number by using $varname so something like...
echo $($varname);
Output:
1
You need to use {} instead of ():
echo ${$varname};
Or even shorter:
echo $$varname;
Which equals:
echo ${'number'};
But as kingkero pointed out: You probably want to do something like ${'number'.$index} and that is easier solved with arrays.