I'm trying to check whether the variable value is false or true, here is my code
$print_ready_flag = $_GET['print_ready']; // i'm passing it as either true or false
echo $print_ready_flag ; // I'm getting correct value
What i'm trying to do is,
if ($print_ready_flag == false) {
file_name = "albumpdf_" . $Order['products_name'] . "_" . $OrderId . "_" . $OrderPId . ".pdf";
}
when doing like above expression is evaluating, But when i tried
if (!$print_ready_flag) {,
if (!(bool)$print_ready_flag)
. expression is not evaluating. Is there any way to evaluate the expression with out using comparison operator.
Well your all conditions are looks fine. you must need to add php `error_reporting() in your code, this will help you to find syntax and warnings.
You have a typo here:
// missing $ sign
file_name = "albumpdf_" . $Order['products_name'] . "_" . $OrderId . "_" . $OrderPId . ".pdf";
And its better to use print_ready=0 instead of print_ready=false for $_GET.
Otherwise, you must need to check with === for value+dataType
$print_ready_flag = $_GET['print_ready'];
echo $print_ready_flag ; // I'm getting correct value
$print_ready_flag = filter_var($print_ready_flag, FILTER_VALIDATE_BOOLEAN);
if ($print_ready_flag == false) {
file_name = "albumpdf_" . $Order['products_name'] . "_" . $OrderId . "_" . $OrderPId . ".pdf";
}
Related
I am having a similiar issue where when I pull a value back from mysql it always returns a -6 when I compare it to a filename. It only happens when I pull the information from mysql
path rp_suzrl250.jpg strFile rp_suzrl250.jpg
strcmp value -6
path 2009_Evo.jpg strFile 2009_Evo.jpg
strcmp value -6
path DSCF6495.JPG strFile DSCF6495.JPG
strcmp value -6
$strFile = $dbrow[bikepicture];
if($dh = opendir($file)){
while(($path = readdir($dh)) !== false){
$path = (string)$path;
$strFile = (string)$strFile;
echo "filename: " . $path . " " . strcmp($path, $strFile) . "<br>";
if ($path === $strFile){
echo $path . " got here " . "<br />";
}
}
}
if (strtoupper($path) === strtoupper($strFile)){ }
Casting to a string fails and going to upper fails. It returns a -6.
My "answer" consists of questions only, but they will likely lead you to a solution.
Is your $strFile a string? What do you get with var_dump($strFile)?
I'd assume, that your code snippet goes inside a loop of this kind:
$results = $cnn->query($query);
while ($dbrow = $results->fetch_array(MYSQLI_ASSOC)) {
...
}
If that is correct, you should use $strFile = $dbrow['bikepicture'], because otherwise bikepicture is interpreted as a constant. Don't you get warnings/errors, by the way?
I've made some progress with my regex that I'm using to extract attributes from pseudo-xml-tags, but then I got ambitous and wanted to correctly handle quoted attributes (with quotes being optional):
regex
~\{language\s*=\s*(P?<quote>[\"\']*)(?P<att>.*?)(?P=quote)\s*/\}~
(this is the output of the var that is used as arg in preg_match, so 'sensible things' such as \" were created with chr(92) . chr(34) beforehand...)
input
kjkjkjkjkjkj{language= 'DE' /}xxxxlxlxlxlllllk
extracts 'DE' when testing with RegexBuddy. But PHPs preg_match issues a warning: Warning: preg_match(): Compilation failed: reference to non-existent subpattern at offset 56.
What's the problem? I thought "quote" was assigned before...
Here's the complete program, just in case I have a PHP-error somewhere:
<?php
$QQ=chr(92) . chr(34);
$delimeters = "{}";
$del0 = preg_quote($delimeters{0});
$del1 = preg_quote($delimeters{1});
$tag="language";
$string="fdfdfdfdf{language=1}testhgg";
$preg1 = "|" . $del0 . $tag . "[^" . $del1 . "]*" . $del1 . "(.*?)" . $del0 . "/" . $tag . $del1 . "|";
$preg2 = "~" . $del0 . $tag . "\s*=\s*(?P<" . "quote>[" . $QQ . "\']*)(?P<att>.*?)(?P=quote)\s*/" . $del1 . "~";
$match=array();
preg_match($preg1,$string,$match);
echo "<br>match1:<pre>";var_dump($match);echo"</pre>";
$match=array();
preg_match($preg2,$string,$match);
echo "<br>match2:<pre>";var_dump($match);echo"</pre>";
?>
Your named subpattern is formatted incorrectly.
(P?<quote>[\"\']*)
should be
(?P<quote>[\"\']*)
See http://php.net/manual/en/regexp.reference.subpatterns.php
Trying to turn this:
href="/wp-content/themes/tray/img/celebrity_photos/photo.jpg"
into:
href="/img/celebrity_photos/photo.jpg"
So I'm simply trying to remove /wp-content/themes/tray/ from the url.
Here's the plug in's PHP code that builds a variable for each anchor path:
$this->imageURL = '/' . $this->path . '/' . $this->filename;
So I'd like to say:
$this->imageURL = '/' . $this->path -/wp-content/themes/tray/ . '/' . $this->filename;
PHP substr()? strpos()?
Given that:
$this->imageURL = '/' . $this->path . '/' . $this->filename;
$remove = "/wp-content/themes/tray";
This is how to remove a known prefix, if it exists:
if (strpos($this->imageURL, $remove) === 0) {
$this->imageURL = substr($this->imageURL, strlen($remove));
}
If you are certain that it always exists then you can also lose the if condition.
This is one option:
$h="/wp-content/themes/tray/img/celebrity_photos/photo-on-4-6-12-at-3-23-pm.jpg";
$prefix="/wp-content/themes/tray/";
print str_replace($prefix, "/", $h, 1);
It suffers from one major flaw, which is that it doesn't anchor itself to the left-hand-side of $h. To do this, you'd either need to use a regular expression (which is heavier on processing) or wrap this in something that detects the position of your prefix before running the str_replace().
$h="/wp-content/themes/tray/img/celebrity_photos/photo-on-4-6-12-at-3-23-pm.jpg";
$prefix="/wp-content/themes/tray/";
if (strpos(" ".$h, $prefix) == 1)
$result = str_replace($prefix, "/", $h, 1);
else
$result = $h;
print $result;
Note this important element: the prefix ends in a slash. You don't want to match other themes like "trayn" or "traypse". Beware writing things for just your specific use case. Always try to figure out how code might break, and program around problematic hypothetical use cases.
Try this :
$href = str_replace("/wp-content/themes/tray","",$href);
Or in your specific case, something like this :
$this->imageURL = '/' . str_replace("/wp-content/themes/tray/","",$this->path) . '/' . $this->filename;
I've been trying to create a directory following a specific structure, yet nothing appears to be happening. I've approached this by defining multiple variables as follows:
$rid = '/appicons/';
$sid = '$artistid';
$ssid = '$appid';
$s = '/';
and the function I've been using runs thusly:
$directory = $appid;
if (!is_dir ($directory))
{
mkdir($directory);
}
That works. However, I want to have the following structure in created directories: /appicons/$artistid/$appid/
yet nothing really seems to work. I understand that if I were to add more variables to $directory then I'd have to use quotes around them and concatenate them (which gets confusing).
Does anyone have any solutions?
$directory = "/appicons/$artistid/$appid/";
if (!is_dir ($directory))
{
//file mode
$mode = 0777;
//the third parameter set to true allows the creation of
//nested directories specified in the pathname.
mkdir($directory, $mode, true);
}
This should do what you want:
$rid = '/appicons/';
$sid = $artistid;
$ssid = $appid;
$s = '/';
$directory = $rid . $artistid . '/' . $appid . $s;
if (!is_dir ($directory)) {
mkdir($directory);
}
The reason your current code doesn't work is due to the fact you're trying to use a variable inside a string literal. A string literal in PHP is a string enclosed in single quotes ('). Every character in this string is treated as just a character, so any variables will just be parsed as text. Unquoting the variables so your declarations look like the following fixes your issue:
$rid = '/appicons/';
$sid = $artistid;
$ssid = $appid;
$s = '/';
This next line concatenates (joins) your variables together into a path:
$directory = $rid . $artistid . '/' . $appid . $s;
Concatenation works like this
$directory = $rid.$artistid."/".$appid."/"
When you're assigning one variable to another, you don't need the quotes around it, so the following should be what you're looking for.
$rid = 'appicons';
$sid = $artistid;
$ssid = $appid;
and then...
$dir = '/' . $rid . '/' . $sid . '/' . $ssid . '/';
if (!is_dir($dir)) {
mkdir($dir);
}
i'm trying to get google steetview tiles and save them. But file_get_contents doesn't like my url:
here's my code:
$img = "http://cbk0.google.com/cbk?output=tile&panoid="+$panorama_id+"&zoom=3&x="+$i+"&y='"+$x+"'";
$url = ""+$panorama_id+"Xval"+$i.+"Yval"+$x+".jpg";
file_put_contents($url, file_get_contents($img));
You're using + for concatenation. That's not PHP. You need the dot . operator instead:
$img = "http://cbk0.google.com/cbk?output=tile&panoid=" . $panorama_id . "&zoom=3&x=" . $i . "&y='" . $x . "'";
$url = $panorama_id . "Xval" . $i . "Yval" . $x . ".jpg";
See string operators in the PHP manual.
Alternatively, with double quoted strings, variables within the string will be parsed. See the manual page for the string type.
$img = "http://cbk0.google.com/cbk?output=tile&panoid=$panorama_id&zoom=3&x=$i&y='$x'";
$url = "${panorama_id}Xval${i}Yval${x}.jpg";