kaz Posted May 6 Share Posted May 6 I need to implement double quotation marks with a line break in an if query. my current code: <script type='application/ld+json'> { '@context': 'https://schema.org', 'sameAs' : [ <?php if ($global->facebook): ?><?= $global->facebook; ?>,<?php endif; ?> <?php if ($global->instagram): ?><?= $global->instagram; ?>,<?php endif; ?> <?php if ($global->linkedin): ?><?= $global->linkedin; ?>,<?php endif; ?> and so on ] } </script> and this is how it should look, if there is an entry: <script type="application/ld+json"> { "sameAs" : [ "https://www.facebook.com/company", "https://www.instagram.com/company", "https://www.linkedin.com/company", and so on ] } </script> <?php if ($global->facebook): ?>"<?= $global->facebook; ?>",\n<?php endif; ?> <?php if ($global->google): ?>"<?= $global->google; ?>",<br /><?php endif; ?> The double quotes work because I used single quotes for the the rest. The line break (\n or br) is not generated in source code. The code is output as text, maybe because it hangs in the echo? The source code looks as follows: "https://www.facebook.com/company",<br /> "https://www.instagram.com/company",\n https://www. How do I set line breaks correctly, in this combination? Link to comment Share on other sites More sharing options...
TomPich Posted May 6 Share Posted May 6 Even if you enter that manually : "sameAs" : [ "https://www.facebook.com/company", "https://www.instagram.com/company", "https://www.linkedin.com/company" ] the browser still skips the line breaks (as shown in the console). I guess you can’t override this behaviour. 1 Link to comment Share on other sites More sharing options...
kaz Posted May 6 Author Share Posted May 6 @TomPich If it can't be changed, it should be fine. Link to comment Share on other sites More sharing options...
BitPoet Posted May 6 Share Posted May 6 Three possible solutions: Add a whitespace after the closing PHP tag Add an empty line after the closing PHP tag Output a real line break. In your example, you're putting a literal \n in the source, outside of PHP. Use <?= "\n" ?> instead. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now