Here's my piece of code(full body code):
<body>
<script type='text/javascript'>
function AddEvent(Syear, Smonth, Sday, Eyear, Emonth, Eday, hallNumber){
...
}
</script>
<?php
function GetMonthByCoding($first , $second , $third) {
...
}
function GetDateByCoding($coding){
...
}
function GetDateFromLine($line){
...
}
$userid = '...';
$magicCookie = 'cookie';
$feedURL = "...";
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->entry as $entry) {
$title = stripslashes($entry->title);
if ($title == "HALL") {
$summary = stripslashes($entry->summary);
$date = GetDateFromLine($summary);
echo ("<script type='text/javascript' language='JavaScript'> AddEvent(" . $date['start']['year'] . ", " . $date['start']['month'] . ", " . $date['start']['day'] . ", " . $date['end']['year'] . ", " . $date['end']['month'] . ", " . $date['end']['day'] . "); </script>");
}
}
?>
</body>
AddEvent() is JavaScript function defined earlier.
What I get in my browser is:
entry as $entry) { $title = stripslashes($entry->title); if ($title == "HALL") { $summary = stripslashes($entry->summary); $date = GetDateFromLine($summary); echo (""); } } ?>
Looks like it was an echo but as you can see there is no echo right in the middle of foreach.
Can anyone say what I am doing wrong?
PHP is not installed, or it is not enabled, or the file is not a .php file or the server has not been told to recognise it as a file to parse.
Try View Source and you should see all your PHP code. The only reason part of it shows up is because everything from <?php to the first > is considered by the browser to be an invalid tag.
I found the problem, it was in the name of variable sxml. I renamed it and the problem escaped.
Related
How can I get the file content from preg_replace?
<?php
function get($it) {
$r = array("~<script src='(.*?)'></script>~");
$w = array("<script type='text/javascript'>' . file_get_contents($1) . '</script>");
$it = preg_replace($r, $w, $it);
return $it;
}
$it = "<script src='/script.js'></script>";
echo get($it);
?>
It returns <script type='text/javascript'>' . file_get_contents(/script.js) . '</script>
If the path is relative as in your example the file_get_contents won't work but this should get you closer:
function get($it) {
return preg_replace_callback("~<script src='(.*?)'></script>~", function($match){
return "<script type='text/javascript'>" . file_get_contents($match[1]) . '</script>';
}, $it);
}
$it = "<script src='/script.js'></script>";
echo get($it);
I'm trying to solve this for some time. I have PHP function that is called on link click. When I click on link it's directing me to this function but it's not giving any results.
Here is how I call function.
foreach ($bandsN as $aa) {
$str = explode(',', $aa);
$next = $str[1];
?>
<?php echo $str[0]?> </div> <?php
if (isset($_GET['other'])) {other($next);}
}
In this function it's called mysql stored procedure with parameter of php function.
function other($var)
{
echo $var;
if (!$mysqli->multi_query("CALL p($var)")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
do{
if($resul = $mysqli->store_result()){
$bands = array();
while($ro = $resul->fetch_row())
{
$bands[] = implode(',', $ro);
}
foreach ($bands as $aa) { ?>
<p > <?php echo $aa?> </p> </div><?php
}
$resul->free();
unset($bands);
}}
while($mysqli->more_results() && $mysqli->next_result());
}
I don't know which is the problem. This code inside function is working because I already have it in other part of app.
If somebody can see what is wrong I would be very grateful.
I have a simple PHP of statement but it keeps giving me 'Internal 500'.
Can anyone see what is wrong with this code?
(It works without the 'if')
$fullyfiltered = preg_replace('/<span>(.*?)<\/span>/', '<div class="chat-message ' if('$1'=="MichaelD"){'me'}else{'chat-midnightblue'}'"><div class="chat-contact"><img src="/assets/demo/avatar/tswan.png" alt=""></div><div id="chat-text" class="chat-text">$1: ', $nearlyfiltered);
EDIT - Full script:
<script>
setInterval(function(){
document.getElementById('chat-text').innerHTML = '';
<?php
$fh = fopen('chat.txt','r');
while ($line = fgets($fh)) {
//echo "<p>" . $line . "</p>";
$filtered = str_replace("'", "\\'", $line);
$almostfiltered = str_replace("<span></span>\n", "", $filtered);
$nearlyfiltered = trim(preg_replace('/\s\s+/', ' ', $almostfiltered));
$fullyfiltered = preg_replace('/<span>(.*?)<\/span>/', '<div class="chat-message ' if('$one'=="MichaelD"){'me'}else{'chat-midnightblue'}'"><div class="chat-contact"><img src="/assets/demo/avatar/tswan.png" alt=""></div><div id="chat-text" class="chat-text">$1: ', $nearlyfiltered);
if(!empty($fullyfiltered)){
$endingp = "</div></div>';";
} else {
$endingp = "';";
}
echo "document.getElementById('chat-text').innerHTML = document.getElementById('chat-text').innerHTML + '" . $fullyfiltered . $endingp;
}
fclose($fh);
?>
},5000);
</script>
callback must be a function, not just random script parts. Please read the manual (http://php.net/manual/en/function.preg-replace-callback.php)
Im getting Parse error from:
$uphalfh = if(isset($price30in)) { echo $price30in->textContent;}
if(isset($price30out)) { echo ", " . $price30out->textContent; }
How can I improve this code to avoid Parse error? I understand that I can't use IF statement in $var
When I Echo Variable's its works like a charm and I get the results that I want. But how can I assign the result of Echo Variable's (on Line:10) to $uphalfh
include_once './wp-config.php';
include_once './wp-load.php';
include_once './wp-includes/wp-db.php';
// A name attribute on a <td>
$price30in = $xpath->query('//td[#class=""]')->item( 1);
$price30out = $xpath->query('//td[#class=""]')->item( 2);
// Echo Variable's
if(isset($price30in)) { echo $price30in->textContent;} if(isset($price30out)) { echo ", " . $price30out->textContent; }
// The wrong CODE i tried:
// $uphalfh = if(isset($price30in)) { echo $price30in->textContent;}
// if(isset($price30out)) { echo ", " . $price30out->textContent; }
// Create post object
$my_post = array();
$my_post['post_title'] = 'MyTitle';
$my_post['post_content'] = 'MyDesciprion';
$my_post['post_status'] = 'draft';
$my_post['post_author'] = 1;
// Insert the post into the database
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id,'30_min',$uphalfh);
$uphalfh = isset($price30in);
if(isset($price30in)) {
echo $price30in->textContent;
}
if(isset($price30out)) {
echo ", " . $price30out->textContent;
}
remove the assignment.
if(isset($price30in)) { echo $price30in->textContent;}
if(isset($price30out)) { echo ", " . $price30out->textContent; }
// $uphalfh = you have to complete the variable initialising here and then continue with the conditional statement or remove the variable initialising and continue with the conditional statement because $var = if(conditon){ }else{ }; is wrong syntax in php
if(isset($price30in)) {
echo $price30in->textContent;
}
if(isset($price30out)) {
echo ", " . $price30out->textContent;
}
echo $uphalf = (isset($price30in)) ? $price30in->textContent : "";
The if clause does not return a value, which means you can't use it in the context of assigning a value to variable because there is no value to be had.
$uphalfh = if(isset($price30in)) {
echo $price30in->textContent;
} if(isset($price30out)) {
echo ", " . $price30out->textContent;
}
The above code will not work as you expected it, the bellow code should work as expected -- the value of $uphalf will be set to either $price30in->textContent or $price30out->textContent.
if(isset($price30in)) {
$uphalfh = $price30in->textContent;
} if(isset($price30out)) {
$uphalfh = ", " . $price30out->textContent;
}
Only if you also want this result to be outputted to the browser (directly visible to a visitor) you could use echo.
if(isset($price30in)) {
$uphalfh = $price30in->textContent;
}
if(isset($price30out)) {
$uphalfh = ", " . $price30out->textContent;
}
echo $uphalfh;
A simple edit did the trick! That solved my problem :-)
I replaced:
$uphalfh = if(isset($price30in)) { echo $price30in->textContent;}
if(isset($price30out)) { echo ", " . $price30out->textContent; }
With this:
$uphalfh = $price30in->textContent. ', ' . $price30out->textContent;
After looking for some Ruby scripts i tried to write on PHP with some help the script.
My Problem is now that I am not sure if the jSon Objects are correct cause I dont know the source for it now.
My Question is if I am making anything wrong with jSon in PHP? If not than the Objects of the Sources are wrong.
<?php
$sn = isset($_GET['sn']) ? $_GET['sn'] : '';
if($sn)
{
$url = 'https://selfsolve.apple.com/warrantyChecker.do?sn='.$sn . "&country=USA";
$json = file_get_contents($url);
$json = substr($json, 5, -1);
$json_obj = json_decode($json);
if(isset($json_obj->ERROR_CODE))
{
echo $json_obj->ERROR_DESC;
}
else
{
echo "$json_obj->PROD_DESCR <img src=\"$json_obj->PROD_IMAGE_URL\" alt=\"\"><br>";
echo"Product Description: $json_obj->PROD_DESCR <br>";
echo"Purchase date: $json_obj->PURCHASE_DATE <br>";
echo"Warranty exp date: $json_obj->COVERAGE_DATE <br>";
}
}
?>
<form action="" method="get" accept-charset="utf-8">
<p><input name="sn" value="<?=$sn?>"><input type="submit" value="Lookup serial"></p>
</form>
Another way I have tried to do it is
<?php
$sn = $argv[1];
$data = json_decode(file_get_contents(
"https://selfsolve.apple.com/warrantyChecker.do?sn=". $sn . "&country=USA"));
echo "Product Description" .$data->PROD_DESCR."\n";
echo "Coverage for " . $sn . " ends on " . $data->COVERAGE_DATE . "\n";
?>
<?php
$sn = isset($_GET['sn']) ? $_GET['sn'] : '';
if($sn)
{
$url = 'https://selfsolve.apple.com/warrantyChecker.do?sn='.$sn . "&country=USA";
$json = file_get_contents($url);
//This line you are splitting the json form then it wont work
$json = substr($json, 5, -1);
$json_obj = json_decode($json);
if(isset($json_obj->ERROR_CODE))
{
echo $json_obj->ERROR_DESC;
}
else
{
echo "$json_obj->PROD_DESCR <img src=\"$json_obj->PROD_IMAGE_URL\" alt=\"\"><br>";
echo"Product Description: $json_obj->PROD_DESCR <br>";
echo"Purchase date: $json_obj->PURCHASE_DATE <br>";
echo"Warranty exp date: $json_obj->COVERAGE_DATE <br>";
}
}
?>