Note: Im the biggest php noob ever!
Right, want i want to do is transform this:
<?php echo "$site_url"; ?>
Into
{site_url}
how would i go about doing it?
If it helps in anyway:
$site_url = 'http://website.com';
| SitePoint Sponsor |
Note: Im the biggest php noob ever!
Right, want i want to do is transform this:
<?php echo "$site_url"; ?>
Into
{site_url}
how would i go about doing it?
If it helps in anyway:
$site_url = 'http://website.com';
Well, if you had this code:
<?php
$site_url = 'http://website.com';
echo '{'.$site_url.'}';
?>
It would output:
{http://website.com}
Is that what you're looking for?
No no, i want: {site_url} to output http://website.com
You might want to hang around and wait for someone else to weigh in on this, because I could be wrong... but I don't think this is possible.
Not without creating a heap of other hoops to jump through, anyway.
You see, PHP is programming code - you have commands that do stuff. If you want to echo something out, you need to run the ECHO command. {} has a very different meaning with PHP.
I am confused, do you want URL to output like {url} or visa versa?
To do the method above, you would need to read the "<a href=''></a>" tag and pull the URL from it.
Otherwise you just have PHP strip the '{'s and echo it in the form of a url link.
One way is much easier than the other.
]
Ok i'm taking a guess at what you are looking for (having a little more information wouldn't hurt here)
PHP Code:$site_url = 'www.domain.com';
$body = "Welcome to {site_url}. Enjoy your stay";
$formatted_body = str_replace('{site_url}', $site_url, $body);
echo $formatted_body;




Good one!!!Originally Posted by dannyf
![]()




You have your answer there from 'Dannyf'Originally Posted by gamerpress
If you wanted the variable itself to be {site_url}...that isn't possible.(as far as I know).
Good luck.
I see now, your question was a little confusing, sorry.
]
Bookmarks