Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
Thread: Basic string question
07-22-2008, 03:40 AM #1
Basic string question
Hey all i am new at PHP so be nice
How can i do the following code in php?
<% dim strName dim strTheName strTheName = "BOB" strName = "Welcome " & strTheName & " to your site!" response.write strName %>
$user_id_name = "BOB"; $html = 'Welcome ' & $user_id_name & ' to your site!"'; echo $html;
Any help would be great!
07-22-2008, 03:59 AM #2
- Join Date
- Sep 2007
- AZ, USA
- Thanked 46 Times in 46 Posts
Almost, it should be
A dot ( . ) is the php equivalent of the asp ampersand ( & ) in this situation.PHP Code:
$user_id_name = "BOB";
$html = 'Welcome ' . $user_id_name . ' to your site!';
07-22-2008, 04:06 AM #3
Yep that did it binaryWeapon.
Thanks for the knowledge!
07-22-2008, 02:44 PM #4
- Join Date
- Jul 2007
- Colorado, USA
- Thanked 0 Times in 0 Posts
While the . is the string join function, a better way to accomplish this example would be:
Unless you really need the string stored as a variable, using echo with commas to separate the parts is faster and better. It will work with the string . to join the parts, but isn't as fast.Code:$user_id_name = 'BOB'; echo 'Welcome ', $user_id_name, ' to your site!"';
Also, the declaration of $user_id_name should be in single quotes, not double as you don't need to have PHP parse any variables inside. It will be faster as well.
Just a few tips to help you out.