Jump to content

need help $url from $value


underbooth

Recommended Posts

Hello.

Its my first time posting here. I got next issue:

My code is this: 

function product_attribute_legatura(){
    global $product;

    $taxonomy = 'pa_legatura';
    $value = $product->get_attribute( $taxonomy );
    $protocol = 'http';  
        $delim = '://';
        $path = 'www';
        $file = $value;
        $url = $protocol . $delim . $path . urlencode($value);
    if ( $value ) {
        $label = get_taxonomy( $taxonomy )->labels->singular_name;
        

        echo '<p>' . '<a href=' . $url;'></a>' . '</p>';
        echo '<p>' . 'Link here:' . '</p>';

Getting $value from database work perfect (its a text filed) I want to make it a link by setting up protocols first time and the web site is retrieved from $value. I concatenate them and i just want to transform it in a link. My code generate a link but like this : http://www.google.com<a (the <a is the issue) need help writing the correct a href output. Thank you in advance

Link to comment
Share on other sites

I would use Barand's suggestion.

 

With that said, your code has a syntax error and that is why it didn't work as you expected:

 

echo '<p>' . '<a href=' . $url;'></a>' . '</p>';

 

You have an extraneous ';' in there.  To fix it would just require:

 

echo '<p>' . '<a href=' . $url . '></a>' . '</p>';

You are doing needless concatenation of string constants which is one reason I would prefer Barand's take. 

However, my opinion is that html attributes should be enclosed within double quotes (even though single quotes are acceptable), so a more complete fix would be:

echo '<p><a href="' . $url . '"></a></p>';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.