So I'm writing this website and i need the following line of code
$b = but the problem is that everything after the // php makes it a comment, so my question is how can I work around this small issue?
So I'm writing this website and i need the following line of code
$b = but the problem is that everything after the // php makes it a comment, so my question is how can I work around this small issue?
The problem is that the PHP parser treats // as the start of a single-line comment when it appears outside a string, so a bare URL like that will break parsing. was on the right track — the quickest fix is to place the URL into a PHP string — and correctly moved to a CMS-side approach when the editor prevented an inline assignment.
Practical alternatives (safe to paste into a PHP file):
$url = 'https://example.com/path'; $url = 'http:' . '//' . 'example.com'; // avoids a contiguous // token outside strings $url = <<<URL
https://example.com/path
URL; If the code must live inside a Joomla site, avoid editing article HTML to run PHP. Put the logic in a template, a module, or a small system plugin so PHP runs where it belongs. In modern Joomla code you can obtain the site base from the CMS API and use it in those files rather than hard-coding strings:
defined('_JEXEC') or die;
use Joomla\CMS\Uri\Uri;
$base = Uri::base(); Security and troubleshooting notes: editors and content filters will strip or neutralize PHP in articles — that’s probably why quoting in the article didn’t work for . Enabling plugins that execute arbitrary PHP in content is possible but increases risk; prefer template/module code, or a vetted content plugin that limits scope. If you still see parse errors, check you have proper PHP tags (<?php ... ?>), a terminating semicolon, and that the file is actually parsed by PHP (not served as plain HTML).
Jump to Post— Member #46692Um...You need to enclose it with speech marks :
$b = "http://www.mydomain.com";
Thanks! it actually didn't work that way, cause joomla wouldn't allow it.
But I resolve the issue by getting the base URL from the joomla API.
Thanks!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.