There seems to be a missing part?

Hi all, have been trying to get this working properly, but can’t seem to figure it out, I was fairly sure I was escaping, unescaping the characters where they should be, but it’s still not coming out right. The code is below:

<?php date_default_timezone_set('GMT');
echo date("l, \\t\h\e\ jS \of F, Y", strtotime("+1 years")); ?>

It should be appearing, as:

Saturday, the 19th of January, 2019

But, instead, it’s appearing as:

Saturday, the 19th of January, 2019

???

Not sure why, but the above last paragraph is appearing above okay, but in reality, it’s coming out with ‘the’ appearing as ‘th-’

I’m not sure about the two enclosing backslashes around “the”
\\t\h\e\

http://php.net/manual/en/function.date.php

And I may not be seeing something obvious, but the “should be” and “instead” look identical to me.

Yep, the way the forums was interpreting it was wrong, but I did amend it.

1 Like

Thanks for the input, I just tried that, and got:
he 19th of January, 2019

(Missing the t)

So it would like this:
\t\h\e jS

Well, the \t is easy. That’s “tab” in viewsource that would not be rendered as such.

As for the \e I’m not seeing that happen when it’s inside a code fence (i.e.backticks). Are you confusing a quote with code block?

Okay, this forum is messing with the code, could you please put the code below in one of your pages and see what results you get. Many thanks. Dez.

<?php date_default_timezone_set('GMT'); echo date("l, \t\h\\e jS \of F, Y", strtotime("+1 years")); ?>

Thank you - so, like this?

<?php date_default_timezone_set('GMT'); echo date("l, \\t\h\e jS \of F, Y", strtotime("+1 years")); ?>

I still don’t get what you mean by “forum messing with the code”, but I do see your problem. It has to do with how PHP works with strings. Variables inside double quotes are parsed, single quotes are string literals. eg

<?php
date_default_timezone_set('GMT');
echo date("l, \t\h\\e jS \of F, Y", strtotime("+1 years"));
echo '<hr>';
echo "\r\n";
echo date("l, \t\h\e jS \of F, Y", strtotime("+1 years"));
echo '<hr>';
echo "\r\n";
echo date('l, \t\h\\e jS \of F, Y', strtotime("+1 years"));
echo '<hr>';
echo "\r\n";
echo date('l, \t\h\e jS \of F, Y', strtotime("+1 years"));
?>

view-source

Saturday, 	he 19th of January, 2019<hr>
Saturday, 	he 19th of January, 2019<hr>
Saturday, the 19th of January, 2019<hr>
Saturday, the 19th of January, 2019

rendered output

I expected the double escaped e to have a backslash in view source which I’m not seeing and don’t know why not. But anyway, put the format inside single quote marks not double.

Sorry Mittineague, which part needs changing?

<?php date_default_timezone_set('GMT'); echo date("l, \\t\h\e jS \of F, Y", strtotime("+1 years")); ?>

As seen in my example code, the format string.

string date ( string $format [, int $timestamp = time() ] )

You could also do this. If you had to add many words all the escaping would get really sloppy.

$a = explode(" “, date(“l, jS F, Y”, strtotime(”+1 years")));
echo $a[0] . ’ the ’ . $a[1] . ’ of ’ . $a[3] . ’ ’ . $a[4];

EDIT:

put the format inside single quote marks not double.
echo date(‘l, \t\h\e jS \of F, Y’, strtotime(“+1 years”));

Better answer to OP’s original post.

I think I figured out the escaped e, it looks like the date function is passed through PCRE where \e is “escape”
http://php.net/manual/en/regexp.reference.escape.php

\e
escape (hex 1B)

EDIT
That looks to be the case

echo bin2hex("\t\h\\e");
echo '<hr>';
echo "\r\n";
echo bin2hex("\t\h\e");
echo '<hr>';
echo "\r\n";
echo bin2hex('\t\h\\e');
echo '<hr>';
echo "\r\n";
echo bin2hex('\t\h\e'); 

(spaces added for readability)


09 5c68 5c65
09 5c68 1b
5c74 5c68 5c65
5c74 5c68 5c65
09 - horizontal tab 
5c - backslash
68 - h
65 - e
1b - escape
74 - t

Thank you all very much, the input above finally cracked it for me, but thank you all - you’re all gems!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.