How do I append characters to a variable in the ECHO command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cre8tor
Forum Newbie
Posts: 18
Joined: Tue Aug 24, 2010 3:58 pm

How do I append characters to a variable in the ECHO command

Post by Cre8tor »

I would like to use the ECHO command to use in a hyperlink. The code I have now is:

<a href="<[ECHO text="category.name"/]>">

This creates a link with the "category.name" variable but the .html extension is missing from the end so it doesn't go to any real page. So I want to append the characters: .html to appear after the category name so it actually goes to a .html page. Can someone help me with the code for that?
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: How do I append characters to a variable in the ECHO com

Post by JakeJ »

Try this:

Code: Select all

$text = 'www.url.com/';
<a href="<?php echo $text.'category.name/'; ?>">Your Text Here</a>
This will output: <a href="www.url.com/category.name/">Your Text Here</a>
Cre8tor
Forum Newbie
Posts: 18
Joined: Tue Aug 24, 2010 3:58 pm

Re: How do I append characters to a variable in the ECHO com

Post by Cre8tor »

I actually had a simple solution: <a href="http://www.url.com/<[ECHO text="category.name"/]>.html">

I ran into another problem though - the <[ECHO text="category.name"/]> outputs the category name in the exact same case lettering that it was typed. For example, if "Travel" was a category name, the link would become http://www.url.com/Travel.html instead of http://www.url.com/travel.html (in lower case). This causes a problem because html pages appear to be case sensitive.

Is there a way to change the text in the echo command to be all lower case letters? If not in the echo command, is there any other way to reduce those letters to lower case for purpose of the link?
Last edited by Cre8tor on Tue Aug 24, 2010 6:07 pm, edited 1 time in total.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: How do I append characters to a variable in the ECHO com

Post by JakeJ »

In php there is a command strtolower() that will do that for you.
Cre8tor
Forum Newbie
Posts: 18
Joined: Tue Aug 24, 2010 3:58 pm

Re: How do I append characters to a variable in the ECHO com

Post by Cre8tor »

Ok, I tried: <a href="http://www.url.com<[ECHO strtolower(text="category.name"/)]>.html"> but that did not work. What would be the proper syntax to apply the strtolower command to my particular case?
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: How do I append characters to a variable in the ECHO com

Post by JakeJ »

I'm a little confused about your method. I'm not seeing php code there. No $ for the variable etc.
Cre8tor
Forum Newbie
Posts: 18
Joined: Tue Aug 24, 2010 3:58 pm

Re: How do I append characters to a variable in the ECHO com

Post by Cre8tor »

This is part of a much longer code generated from link building software. The category.name is actually a variable which is defined at an earlier stage. That's the reason why my line works without the $ symbol.

But to make this as simple as possible, how can I reduce that variable, category.name, to lower case letters for that line only?
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: How do I append characters to a variable in the ECHO com

Post by JakeJ »

Since I don't know your link building software I have no idea. It will probably have to be done before you pass the link to the link building stuff.

But if you run the variable through strtolower() BEFORE you pass it to the link building software it should work.
Cre8tor
Forum Newbie
Posts: 18
Joined: Tue Aug 24, 2010 3:58 pm

Re: How do I append characters to a variable in the ECHO com

Post by Cre8tor »

What would be the command to make the variable, category.name, to appear in lower case letters? I tried: strtolower(category.name) just before the line but that didn't work.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: How do I append characters to a variable in the ECHO com

Post by JakeJ »

It's only going to accept a valid php variable name or properly formatted string. So you'll have to do strtolower($variable_name). Or, in html mode <?php strtolower($variable_name); ?>

I don't know what else to tell you other than to try to convert the actual variable BEFORE it gets passed to your software at all, but i'm not sure if that's possible.
Post Reply