I have an input field in html where I want to echo the value of datetime stored in mysql.
<input type="datetime -local" name="schedule" value="<?php echo $result['schedule']; ?>
But despite the value being there in mysql db as YY/mm/dd h:m:s the value is not showing up. What could be the possible issue? When I try to echo outside the input value it displays the result. My thoughts are that the datetime needs formatting according to the html datetime -local input field.
Please suggest me any way if possible.
T is a format character(Timezone abbreviation e.g: EST, MDT…) so you can't use it directly. Escape it (\T) to get a literal T character:
datetime.format.php
You can prevent a recognized character in the format string from being expanded by escaping it with a preceding backslash.
<?php
$date = date("Y-m-d\TH:i:s", strtotime($result['schedule']));
?>
<input type="datetime-local" name="schedule" value="<?php echo $date; ?>"/>
use <?=$date?> instead of <?php echo $date; ?>
You are filling it the wrong way. Read the documentation about the input-type datetime-local The correct format is YYYY-MM-DDTHH:MM - note the T as divider between date and time.
Also:
you wrote the type wrong. Correct is datetime-local
you are missing the closing quote at the value attribute.
This is how to fix it
<input type="datetime-local" name="schedule" value="<?php echo $date = date("Y-m-d\TH:i:s", strtotime($result['schedule']));?>">
Related
I know if I'm concatenating strings in php I can use the . operator with a empty set of quotes ' ', but how do I concatenate a space on the end of a function in php?
In the code below I want to add a single character space after the date function inside the php delimiters so there is a space between the date and the company name. I don't want to use   in the HTML.
<span id="footer-year"><p><?php echo date(Y); ?></p></span><p>The Company Name</p></div>
You can just echo it out with concatenation:
<?php echo date('Y') . " "; ?>
Note that you need quotes around your Y in date().
Also note that a <p> tag cannot reside within a <span> tag, as <span> is inline and <p> is block-level. That would result in invalid markup. You can validate your markup with the W3C Validation Service.
What you're probably looking for is:
<span id="footer-year"><?php echo date('Y') . " The Company Name" ?></span>
Which will be outputted as:
<span id="footer-year">2017 The Company Name</span>
Hope this helps :)
Currently i'm trying to send a time and a date from php to my angular controller by using a ng-click.
$time is a date
$today is a datetime
Can someone explain me why this works
<button ng-click="getClickInfo('<?php echo $time; ?>', '<?php echo $today; ?>')";</button>
But when i try to achieve the same result within an echo like this, it gives me different and incorrect output
<?php echo '<button ng-click="getClickInfo(' . $time . ', ' . $today . ')";></button>'; ?>
I tried to search on the internet for a solution but i couldn't really find a topic about it. Hope someone can explain me what is happening in this scenario. Redirection to any articles on this topic would be really helpfull for me.
Output:
01:00 // incorrect output
01/01/1970 // incorrect output
20.30 // desired output
22-04-2016 // desired output
You have to quote the javascript function arguments, otherwise you get unpredictable results
The ctach here is that the HTML ng-click attribute must be enclosed in double quotes and the attribute value (your function) must not contain double quotes, because it would break the HTML
Furthermore, the ; is not needed, you're putting it outside the ng-click HTML attribute value, that is not valid HTML
Here's a fix, note that quotes are escaped with backslash inside PHP strings:
<?php echo '<button ng-click="getClickInfo(\'' . $time . '\', \'' . $today . '\')"></button>' ?>
Here's a more readable way to do it, I would recommend this approach:
<?php echo '<button ng-click="getClickInfo(' . "'$time', '$today'" . ')";></button>' ?>
I've got a PHP problem. When I have the following array:
$string = array('<','s');
echo $string[0];
echo $string[1];
Nothing is showing
It prints fine if I put any other special character or integer value in place of the 's'
$string = array('<','1');
echo $string[0];
echo $string[1];
output: <1
OR
$string = array('<','1#');
echo $string[0];
echo $string[1];
output: <#
I assume that your output is not being shown to you as expected because you are looking at it in a web browser. Anything starting with a < character followed by a letter is going to be interpreted as an HTML tag.
If you look at the page source of your output, you will probably see what you are looking for.
I'm sure PHP has a way to output escaped HTML tags and such out to a page, but I'm not familiar with it.
$string = array('<','s');
echo htmlentities($string[0]);
echo htmlentities($string[1]);
when you echo '<', the browser assumes you opened a tag name & expects '>'. as you know, content inside < & > is a tag & doesn't show on output(tags are used for formatting & sometimes styling the page). so, use echo htmlspecialchars($string[0]) instead.
Less than and more than-characters are typically used for defining elements in your html, therefore you must define that these characters should be output like "normal characters" instead:
< = less than (<)
> = more than (>)
In your example:
$string = array(<,'1');
Take a look at http://www.ascii.cl/htmlcodes.htm and look in the "html name column"
You could aslo have a look at http://php.net/htmlentities
I'm retrieving values from MySQL numeric field and want to format with a comma separator for 1000s like this: 21,000
This code below seems to work for display - how do I strip out the commas again before updating and inserting into MySQL DB?
<input type="text" name="Price id="Price value="<?php echo number_format($row_['Price'])); ?>" size="10" />
Thanks .........
You can use the numberFormatter class for both making and stripping the formatting around values quite nicely:
You can format easily with format()
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(intl_is_failure(numfmt_format($fmt))) {
report_error("Formatter error");
}
?>
Output
1.234.567,891
Then, the parse() function will let you remove whatever formatting you applied to get back to your original format.
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo numfmt_parse($fmt, $num)."\n";
echo numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)."\n";
?>
Output:
1234567.891
Note: Keep in mind that if you are passing these things in forms and back and forth, you will potentially lose decimal places or the like if you format them down.
Not sure I understood your question correctly, but you could remove the character with str_replace...
str_replace(",", "", $Price);
I am getting wrong output i.e. 1194908400
None of this is working i.e. I tried to put double quotes around variable, tried without quotation marks. result is same and wrong.
$d='07-11-13';
echo $d;
echo strtotime($d);
echo "<br>";
echo strtotime("$d");
After a few checks, the error is actually NOT in the format you're passing, but rather on the way you're passing it.
What you should do is just replace "13" with "2013":
strtotime("07-11-2013");
output: 1383778800
echo strtotime("2013-11-07");
output: 1383778800
echo strtotime('07-11-13');
output: 1194908400
The problem is you need to specify a 4 digit year, so that strtime can fully work out which date format you are using. With 07-11-13 it probably thinks you are using 2007-11-13.
Change it to 07-11-2013 and you will get the correct answer.
$d='07-11-13' is wrong, Try this
$d='2013-11-13';
echo $d;
echo strtotime($d);
echo "<br>";
echo strtotime("$d")
strtotime() will accept:
m/d/y
d-m-y
With / it expects month/day and with - it expects day-month.