string concatenation problem

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
neclark2
Forum Newbie
Posts: 3
Joined: Thu Jun 12, 2008 3:33 pm

string concatenation problem

Post by neclark2 »

I'm developing a simple webpage right now that queries a user database and outputs a table of information relating to the members. One of the fields that I'm trying to output is the member e-mail and this is the part that is giving me trouble. In my code, I can get to the part where I have a variable called $member_email just fine, the part I cannot figure out is how to properly output the e-mail as a "mailto" link. This is what I have come up with:

Code: Select all

 
echo ("<a href = \" mailto: $member_email \" > $member_email </a>
 
this just seems to display the literal text $member_email.. I have tried a lot of variations but all seem to do the same thing or give parser errors....

any help would be greatly appreciated :D :D
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: string concatenation problem

Post by VladSun »

Code: Select all

echo '<a href = "mailto:' . $member_email . '">' . $member_email . '</a>'
There are 10 types of people in this world, those who understand binary and those who don't
neclark2
Forum Newbie
Posts: 3
Joined: Thu Jun 12, 2008 3:33 pm

Re: string concatenation problem

Post by neclark2 »

it works!!! thanks
neclark2
Forum Newbie
Posts: 3
Joined: Thu Jun 12, 2008 3:33 pm

Re: string concatenation problem

Post by neclark2 »

so is the moral of the story here to always surround parts of strings containing double quotes with single quotes and to always use the . operator to combine literal strings with variables?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: string concatenation problem

Post by VladSun »

I prefer it this way :) - I think it's more readable.
I don't like the string-variable parsing feature of PHP. Also, I don't like the difference between "\n" and '\n' and you have to pay attention about this too.
There are 10 types of people in this world, those who understand binary and those who don't
mpetrovich
Forum Commoner
Posts: 55
Joined: Fri Oct 19, 2007 2:02 am
Location: Vancouver, WA, USA

Re: string concatenation problem

Post by mpetrovich »

I don't like the string-variable parsing feature of PHP.
I wish they gave us back single quotes(`) as a third option.

Here is a strange way to do this.

Code: Select all

function qq($text) 
{ 
    return str_replace('`','"',$text); 
}
 
function printqn($text) 
{ 
    echo qq($text)."\n"; 
}
These functions just replace back single quotes with double quotes.

So, the using this, the code would be:

Code: Select all

printqn("<a href =`mailto:$member_email`>$member_email </a>");
I found I made less errors using this.
developing a simple webpage right now . . .outputs a table of information relating to the members. . .member e-mail
I hope this is a private members-only Web page, and even so, you do not want to output e-mail address to anything public, or you will open your members up to spam. I know you want to keep this simple, but it is usually better to have a contact form and let people send messages to a member that way.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: string concatenation problem

Post by Ollie Saunders »

mpetrovich, is going a bit off-topic there.

The truth is neclark2 there are loads of different ways to structure string data in PHP. I'd say it probably overly complex but it is worth learning what all the ways of doing it are. They each of their pros and cons and you'll need to know them all because you'll see other programmers using the full range of syntaxes.

The best way to learn them is to read the manual on strings http://php.net/manual/en/language.types.string.php Try all the different things out. Strings are so fundamental to PHP this is something worth spending some time on.
mpetrovich
Forum Commoner
Posts: 55
Joined: Fri Oct 19, 2007 2:02 am
Location: Vancouver, WA, USA

Re: string concatenation problem

Post by mpetrovich »

mpetrovich, is going a bit off-topic there.
Agreed. Sorry, probably not helpful for someone learning the language.

I do hope the point is taken not to provide public e-mail.
Post Reply