Make text a link in php inside div

Hi there :slight_smile: I need some help with something that most would probably find very easy, but for me, it’s hard, lol. I am using a script and trying to do some customization. For example, I want to make this text inside this div clickable. Can someone provide me the correct me ?

$result['html'] = '<div class="alert alert-success">' . htmlspecialchars($amount) . " satoshi was sent to you on <a target=\"_blank\" href=\"".$this->check_url."\">$sname</a>. Service provided by example.com</div>";

I need to have the example.com be a link. I appreciate any help you can provide.

like this you mean?


$result['html'] = '<div class="alert alert-success">' . htmlspecialchars($amount) . ' satoshi was sent to you on <a target="_blank" href="' . $this->check_url . '">$sname</a>. Service provided by example.com</div>';

Hi, thanks for taking the time to help. I appreciate it. I just tried your line of code, and it has changed nothing. I will upload a picture, for example. In the photo, you can see CryptoBagGiver.com is not clickable like faucetpay.io, Thanks.

The way to solve this would be to lookup the syntax for an anchor/link tag, if not already known - <a>: The Anchor element - HTML: HyperText Markup Language | MDN then produce the html markup that does what you want. I recommend you try to do this yourself, thereby learning how to do it, rather then to just repeat something someone else posts for you to copy.

I tried, but I keep getting syntax error, looks like there’s a unique way to insert it in this line of code.

You would need to post your attempted code, and the error you were getting, in order to get help with what is wrong.

Dont post mis-matched examples either.

Your provided example does not match your image example. I dont recall seeing you needed ‘example.com’ made the link.


$result['html'] = '<div class="alert alert-success">' . htmlspecialchars($amount) . ' satoshi was sent to you on <a target="_blank" href="' . $this->check_url . '">$sname</a>. Service provided by <a href="http://example.com" target="_blank">example.com</a></div>';

As phdr mentions… you really should give things a ‘try’ yourself… this is basic HTML 101…

Hi, thanks for the reply, am sorry for the mismatch I forgot to change the code when I took the screenshot, At first I used example.com before the screenshot to not make it look like I am spamming but I did not think about it when I took a screenshot. Alright now onto the help :slight_smile:

Your code works no more syntax errors but I see you had to change a few things I would not consider basic HTML :slight_smile: . I see that this line…

. htmlspecialchars($amount) . " satoshi was sent to you on <a target="_blank" href="".$this->check_url."">$sname.

changed to this…

. htmlspecialchars($amount) . ’ satoshi was sent to you on <a target="_blank" href="" . $this->check_url . '">$sname.

and that as stopped the syntax error when adding a simple href.

Now I have a new issue :slight_smile: The code I provided is not the only one I need to change there’s another line that’s slightly different but I will try to understand what you had to do and try to apply it to this line…

$result[‘html_coin’] = ‘

’ . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), ‘0’), ‘.’)) . " " . $this->currency . " was sent to you on <a target="_blank" href="".$this->check_url."">$sname. Faucet provided by example.com
";

Thanks.

The general rule/understanding here is:

If you have a dynamic value/variable… you need to break the string, concatenate the dynamic variable, and then continue on with the string.

'Some string here'
vs
'Some string here' . $variableName . ' with added dynamic variable added';

Note:

the above posted line of code is also wrong then… IF you need $sname parsed… if so… then you need ot do this:

$result['html'] = '<div class="alert alert-success">' . htmlspecialchars($amount) . ' satoshi was sent to you on <a target="_blank" href="' . $this->check_url . '">' .$sname .'</a>. Service provided by <a href="http://example.com" target="_blank">example.com</a></div>';

And the comment about normal HTML 101 was about the ‘example.com’ reference…

That was nothign but normal HTML

example.com
vs
<a href="http://example.com" target="_blank">example.com</a>
1 Like

Thank you for the explanation really appreciate it :slight_smile:

Your last line of trouble…

1.) NEVER (ever) use fancy quotes… only use double quotes (") or -normal- single quotes (’)
2.) You need to learn/understand the difference between, how/when (and how it affects things) using single or double quotes. You have to follow suit and you can NOT co-mingle them

If you start with a single ’ or double " quote… you must end with that. When you break up your ‘string’ to add in dynamic variables… you need to break the string using the same quote you started with:

Compare the differences/changes


$result[‘html_coin’] = ‘

’ . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), ‘0’), ‘.’)) . " " . $this->currency . " was sent to you on <a target="_blank" href="".$this->check_url."">$sname. Faucet provided by example.com

";

vs

$result['html_coin'] = '' . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), '0'), '.')) . " " . $this->currency . ' was sent to you on <a target="_blank" href="' . $this->check_url . '">' . $sname . 'Faucet provided by <a href="http://example.com" target="_blank">example.com</a>';
1 Like

Hi, for the other line I need to fix would this be correct…

From

$result['html_coin'] = '<div class="alert alert-success">' . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), '0'), '.')) . " " . $this->currency . " was sent to you on <a target=\"_blank\" href=\"".$this->check_url."\">$sname</a>. Faucet provided by example.com</div>";

to

$result['html_coin'] = '<div class="alert alert-success">' . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), '0'), '.')) . " " . $this->currency . ' was sent to you on <a target=\"_blank\" href=\"".$this->check_url."\">$sname</a>. Service provided by <a href="http://example.com" target="_blank">example.com</a></div>';

All I did was a change from " to ’ just before was sent to…

Now am trying to understand what you recommended regarding the $name going from this

. ‘">$sname. to . ‘">’ .$sname .’.

For the $name do I need to do this? the code is from a script and it’s like this all over the place.

I also noticed this

" href=" was changed to this href="’

Can you help me understand what the backslash does and why it’s removed?

He’s not. This is due to the forum software.

@DGTAL, please use bbcode [code][/code] tags around your code, instead of block-quotes. This will cause the code to be highlighted and formatted as code without the quotes being shown as smart/curly quotes.

Ok, thank you for the information I was trying to do that but could not find the button on the editor :slight_smile:

Was looking ok I think until you got here:

' was sent to you on <a target=\"_blank\" 
href=\"".$this->check_url."\">$sname</a>. Service provided 
by <a href="http://example.com" 
target="_blank">example.com</a></div>';

You started with a single quote… then break/stop the string using " to attempt to add in the PHP var.

The backslahes are not needed. (in this instance at least)… but if you were using " (double quotes) to declare your string, and you need to have a " inside your string… you would use a backslash to escape it… so it would not be ‘seen’ as the end of the quote (per se`)…

You have an example posted above you can use to compare.

1 Like

Hi, I spoke too soon :frowning:

When I said your code worked, I was referring this off my editor, not pointing out the syntax error, but when I went to try the function, the name thing shows on the website like this…
$name

I think il leave this as standard text. My head going to explode, lol

You missed the update (which was done almost ASAP I believe)

you can go back and check the comparison as well.

And this should be a GREAT test for you to fix. its VERY simple. If you want that $sname variable to not be STRING/TEXT (but really show the variable value)…

Then you would split the string… (add variable) and then concatenate the strong again to continue on.


$result['html_coin'] = '' . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), '0'), '.')) . " " . $this->currency . ' was sent to you on <a target="_blank" href="' . $this->check_url . '">' . $sname . ' Faucet provided by <a href="http://example.com" target="_blank">example.com</a>';

VERY simple:

 $sname 
vs
' . $sname . '
1 Like

Thank you so much :slight_smile: You are sharp let me tell you, I wish I was able to retain information and understand like you :slight_smile:

Thank you so much, everyone.

$result['html'] = '<div class="alert alert-success">' . htmlspecialchars($amount) . ' satoshi was sent to you on <a target="_blank" href="' . $this->check_url . '">' . $sname . '</a>. Faucet provided by <a href="https://example.com" target="_blank">example.com</a></div>';
$result['html_coin'] = '<div class="alert alert-success">' . htmlspecialchars(rtrim(rtrim(sprintf("%.8f", $amount/100000000), '0'), '.')) . " " . $this->currency . " was sent to you on <a target=\"_blank\" href=\"".$this->check_url.'">' . $sname . '</a>. Faucet provided by <a href="https://example.com" target="_blank">example.com</a></div>';
Sponsor our Newsletter | Privacy Policy | Terms of Service