String PHP Spell Wrongly [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
PHP spelling frustrated me. I keep trying to add ". ABC ." and '. ABC .'. But it still doesnt work. Like my code below:
echo '
<div class="box">
<p> '.$obj->name.': "'.$obj->message.'" </p>
<p class="right"> '.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.' </p>
</div>
';
The problem is DATE FORMAT doesn't want to show on a webpage. Any idea?

Change
'.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.'
to
'.date_format($obj->message_date, 'Y-m-d H:i:s').'
If $obj->message_date is a string, you need to convert it to a date object first:
'.date_format(date_create($obj->message_date), 'Y-m-d H:i:s').'

The issue you are having is you are not concatenating your PHP into your string correctly.
echo '
<div class="box">
<p> '.$obj->name.': "'.$obj->message.'" </p>
<p class="right"> '.date_format($obj->message_date, "Y-m-d H:i:s").' </p>
</div> ';
I think this should not provide errors on that front. If the page still doesn't load you will need to look at the $obj to see if there is actually a message_date property and that is a date.
For more information see http://php.net/manual/en/language.operators.string.php

Related

$_GET . Undefined Variable. Cant find solution [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm having an issue and am out of ideas.
I'm trying to get a parameter from the URL, but PHP insists in saying that the variable is not defined.
The URL is
http://localhost/trendwatcher/index.php?date=2014-10-18
And the script is something like
<?php include "header.php"; ?>
<section id="stats">
Showing trends for <?php echo $GET_["date"]; ?>
</section>
And finally, the error:
Showing trends for
Notice: Undefined variable: GET_ in C:\xampp\htdocs\trendwatcher\index.php on line 4
Does anyone have any ideas?
Thanks!
Fix your code from:
<section id="stats">
Showing trends for <?php echo $GET_["date"]; ?>
</section>
to
<section id="stats">
Showing trends for <?php echo $_GET["date"]; ?>
</section>

PHP code is not working in html tags [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So, I am creating my own error page. And it takes some information from the url.
Here is a code in the top of the error.php
<?php
$error_message = $_GET["error_message"];
if(!$error_message) {
$error_message = "вы оказались здесь из-за сбоя в работе программы.";
}
echo $error_message;
?>
And it works fine. But when I am trying to echo this vatiable in my html code below, nothing happens:
<p>Нам очень жаль, но произошел сбой. Вероятно, <span class="error"><?php echo $error_messsage ?></span>.</p>
I really cant understand, where my problem is.
Thanks for any help.
There's a spelling error in your HTML code. It should be:
<p>Нам очень жаль, но произошел сбой. Вероятно, <span class="error"><?php echo $error_message ?></span>.</p>
One too many "s"s in the variable name in your original code.
Typo error sir :)
<p>Нам очень жаль, но произошел сбой. Вероятно, <span class="error"><?php echo $error_message ?></span>.</p>
Too many s on $error_message;

php - inline font style for print statement? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I know its possible to apply inline styles to echo statements but can this be done with print statements as well?
In my pagination I have links to previous and next records using the greater and less than symbols <> and a running count of the current record against the total number of records. e.g.
<
1/2
or
>
2/2
I have styled them in css but want to decrease the size of the count only. If I make changes to the css the font size for the previous and next links and count all change, I only want to target the count.
<div class="nextcard"><?php if($nextlink != ""){ print ($nextlink."<br/>".$next."/".$count); } ?></div>
I have tried :
<div class="nextcard"><?php if($nextlink != ""){ print 'style=font:50px' ($nextlink."<br/>".$next."/".$count); } ?></div>
But get syntax errors.
One approach would be to add a class rather than inline styles. However, you have forgotten to append the string correctly.
Here is what I would personally do: (Note I replaced print with echo, TBH, there would be no different)
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span class="mark">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>
If you still want to style it inline, you should simply do:
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span style="font-size:50px;">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>

PHP form Echo change format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a mobile number
0827910119
this is how it is saved in SQL, if I echo it back on a form i would like to have it shown as follow
27827910119
This is my echo command
<input type="text" name="member_msisdn" value="<? echo $rows['member_msisdn']; ?>"
readonly id="member_msisdn" />
I have tried a Session command to drop the 0 and add the 27 in front but not getting it to work
$_SESSION['msisdn'] = "27" . substr($rows['member_msisdn'], 1);
Is there another way I can echo the number to drop the 0 and add the 27 as I need the 27827910119 in my action PHP to work and not the 0827910119 number
Use
$rows['member_msisdn'] = "27" . substr($rows['member_msisdn'], 1);
instead of
$_SESSION['msisdn'] = "27" . substr($rows['member_msisdn'], 1);
or print using
<? echo $_SESSION['msisdn']; ?>

php foreach() error message [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm creating a mobile website that takes feeds from a rss link and displays it as list..
here is my code
<div data-role="content">
<ul data-role="listview" data-theme="c" data-dividertheme="a" data-counttheme="a">
<?php
foreach($feed->query->results->item as $item) {
?>
<li>
<a href="article.php?notices=<?php echo $siteName;?>&origLink=<?php echo urlencode($item->guid->content);?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
</div>
but this is showing an error on line 12! which is below foreach($feed->query->results->item as $item)
EDIT:
Thanks everyone for your help. The rss link had slow response time so the YQL was timing out.. but now it's working..
Try to check for is_array like
if( is_array($feed->query->results->item) ) {
foreach($feed->query->results->item as $item) {
//The run the foreach loop
}
}
An if it is not an array then print the single result.Even we need to check whether they are getting results or not.
This is just guesswork but I think $feed->query->results->item is not an array. What you meant was $feed->query->results perhaps?
foreach ($feed->query->results as $item) {
// Do stuff
}
I think $feed->query->results->item this is empty. So it would be great if You provide the output of $feed.
then it will be easier to give You the exact result.
$feed->query->results->item is not an array ... or nothing is returning from the DB .. try to var_dump($feed->query->results->item) before the foreach and check if you are looping on the right value

Categories