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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.