First of all, I have really limited knowledge with php. This is the code I use to show a ref for the unique person visiting the page.
<p>http://mywebsite.com/?ref=<? echo $ref; ?></p>
I also have a Facebook Share that is suppose to copy the ref url and add it.
$url=urlencode('http://mywebsite.com?ref=<? echo $ref; ?>');
Obviously this won't work.
$ref=123;
$url='http://mywebsite.com?ref='.urlencode($ref);
echo "$url<br>";
--> http://mywebsite.com?ref=123
I don't think you want this:
$url=urlencode("http://mywebsite.com?ref={$ref}");
echo "$url<br>";
--> http%3A%2F%2Fmywebsite.com%3Fref%3D123
Your call to urlencode() is in your PHP script, right? No need to use echo for that. Just pass $ref as part of the string that you're passing into urlencode().
$url = urlencode("http://mywebsite.com?ref={$ref}");
Make sure you use double-quotes as I've shown. Single quotes will cause PHP not to recognize {$ref} as a variable name.
You can add a variable to a string with a period, like this:
$url=urlencode('http://mywebsite.com?ref=' . $ref);
Alternatively, you can enclose the string in double quotes and then reference the variable directly in the string with curly brackets:
$url=urlencode("http://mywebsite.com?ref={$ref}");
The PHP manual is very useful when you want to learn the PHP language. Read about strings here: http://www.php.net/manual/en/language.types.string.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.