PHP If Then statement based on numeric range from field output [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a number field: <?php echo $entity->field_zip_code_name[0];?>
I want to create an if then statement based on the output number. Here is what I have:
if ($entity->field_areacode[0] = 92919,92923,94975,37783) {
<h3 style="font-size: 20px;"><strong>Area Code:</strong></h3>;
}
else {
NONE;
}
any help would be greatly appreciated.

Not sure what x is, if it's $entity->field_zip_code_name[0] then echo that:
if(in_array($entity->field_zip_code_name[0], [92919,92923,94975,37783])) {
//display x
}
If your PHP version doesn't support [] then use array():
if(in_array($entity->field_zip_code_name[0], array(92919,92923,94975,37783))) {
//display x
}

Related

Php function with return statement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Can somebody explain me this code? I don't understand why it outputs 21.
<?php
function math($t){
if($t==0)
return 0;
return $t+ math($t-1);
}
echo math(6);
?>
It will echo 21. I have no idea how it got this result.
The function is recursive, it calls itself until it gets to 0, then adds all the previously returned values (6,5,4,3,2,1).
function math($t){
if($t==0)
return 0;
return $t+ math($t-1);
}
echo math(6);
So on loop one it gets 6 then 6-1 = 5 so math gets called again with 5 this time and so on. Take a look at http://sandbox.onlinephpfunctions.com/code/e228f3b696c5058efee03fa978a09179c1f2ffbb.

HTML code gets displayed when it should not [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the following PHP code:
<?php
$obrazek = the_post_thumbnail( 'product_page_image' );
list($nic,$nic,$nic,$nic,$nic,$obrazeklink,$nic,$nic,$nic,$nic,$nic) = explode('"', $obrazek);
?>
and $obrazek variable contains
<img width="1560" height="1170" src="http://takopix.com/wp-content/uploads/edd/2015/06/Melbourne-storm-1560x1170.jpg" class="attachment-product_page_image wp-post-image" alt="Melbourne storm">
but the HTML gets recognized even without echo... and explode doesn't work!
The function the_post_thumbnail is used to print the thumbnail markup. It returns nothing. You want get_the_post_thumbnail

line break conversion from html to php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have html code loaded in array $gh[0] and i am coonverting it to plain text
if i compare with same text loaded into new variable it doesn't works
can someone help with the issue, what should be exact value in $a to match the content in $gh[0]
i want comparsion to be working , what will be output if $gh[0] is converted into plain text especially line break
<?php
$gh[0]="Net inventory (used in)/from<br>Production Activities"
$fg=$gh[0]->plaintext;
$a="Net inventory (used in)/from Production Activities"
if($a == $fg)
{
echo "match";
}
else
{
echo "No match";
}
?>
What about just stripping all elements from the input?
$gh[0]= strip_tags($gh[0]);
If you want to know what the value (of $fg) is, why don't you check it?
There's echo, print_r and var_dump.

How to format a string returned by a PHP function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote a program that uses an ISBN to query Amazon for that ISBN's price, and returns the following result:
5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.98241010000
I need to format this so that I have the price information in a format that would be understandable to a human.
How can I do this?
Use this way..
<?php
$s = '5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.982410100000';
$p = explode('USD',$s);
echo "<pre>";
print_r($p);
echo "</pre>";
?>
function returnPrice($response){
$prices = explode('USD',$response);
unset($prices[0]);
return $prices;
}

PHP - Creating custom variable for template [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I don't know exactly how to say this, I'll use an example.
//[$var:Username|n] will print username with n length
$myText = 'The participants are [$var:Username|10], [$var:Username|8], and [$var:Username|6]';
$username = array('Alexandrite', 'Maximillian', 'Angelina');
$result = someFunction('[$var:Username|n]', $username, $myText);
echo $result;
//The participants are Alexandrit, Maximill, and Angeli
Any idea how to do this? Maybe using preg_replace?
I'm interested to know why you would even need to do this. Regardless:
preg_replace_callback('/\[\$var:Username\|(\d+)\]/', function ($match)
use (&$count, $username
) {
return substr($username[$count++], 0, $match[1]);
}, $myText);

Categories