Skip to content
Advertisement

Interpret PHP inside a quote in a PHP

I have this variable $url that I need to print inside a quoted HTML that it’s inside a PHP if conditional.

JavaScript

But src="$url;" is interpreted as src="$url;" in the HTML code. It does not interpret as a variable.

How can I solve that?

Advertisement

Answer

I like to seperate the business logic from the output. This, in combination with PHP’s alternative syntax for control structures, keeps your HTML output clean and easily readable.

See this example:

JavaScript

Since the first part of the if-statement is empty, you can simplify the code:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement