Escaping Characters in PHP

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
bookfiend
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Mar 07, 2018 3:04 am

Wed Mar 07, 2018 3:10 am

I am a newbie to coding with php and I for some reason cannot figure something out with using the escape character. I have spent over an hour trying to figure something out so simpe by trying different syntax and googling it, and checking online php syntax errors but to no avail. Below is the php code that I am trying to run and the error message that I am getting is special characters must be escapted [<]

So, what is wrong with my code and how can I fix it?

<?php echo ‘<p>Testing my new PHP function</p>’; ?>

chorn
php-forum Fan User
php-forum Fan User
Posts: 552
Joined: Fri Apr 01, 2016 2:18 am

Wed Mar 07, 2018 3:26 am

For strings you can use single- or double-quotes. What you posted is none of these, they are backticks.

bookfiend
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Mar 07, 2018 3:04 am

Wed Mar 07, 2018 3:43 am

Thank you for the quick reply. I tried to use double quotes but I am still getting the following error:

Testing my new PHP function
";?>

And here's all of the code with the php:

<!doctype html>
<html>
<head>
<title>This is a Simple PHP Page</title>
</head>
<body>
<?php echo "<p>Testing my new PHP function</p>"; ?>
</body>
</html>

User avatar
phpRob
New php-forum User
New php-forum User
Posts: 65
Joined: Mon Feb 26, 2018 7:15 am

Wed Mar 07, 2018 4:24 am

The answer about the single/double quotes was correct, so do remember that.
I did a quick sanity check and I don't get the output you say you do. Looked like it would work fine and it does. Verify what you are saying matches the code you are actually using please.

Post Reply