I'm a total php newbie.. help on simple 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
th3monk3y
Forum Commoner
Posts: 29
Joined: Thu Jun 19, 2003 10:34 pm

I'm a total php newbie.. help on simple problem..

Post by th3monk3y »

Hi All,

This should be a breeze for you guys... I just started messing around with php couple days ago and I am stuck...

i need to echo some javascript and i am not sure where to put in all the back slashes! \ I keep getting errors and more frustrated!

this is what i need to echo

<a href="javascript:;" onClick="MM_openBrWindow('http://www.mydomain.com/path/path/','', ... 15,left=15')"><img src="http://www.mydomain.com/path/path/unavailable.gif"
border="0" alt="my alt text"></a>

thanks in advance,
-Paul
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post by trollll »

When in doubt, use the addslashes function. In general, you need to add slashes to ", ', \ and null bytes. The link tells all... :)
th3monk3y
Forum Commoner
Posts: 29
Joined: Thu Jun 19, 2003 10:34 pm

magic quotes?

Post by th3monk3y »

I don't know if it matters with the link you sent me, but I have magic quotes turned off in order to make another php program run properly.. is there a general rule of thumb here? I am sort of looking for the short quick answer... I have been looking at other php examples and noticed the back slashes behind all the =
thanks,
-paul

<a href=\"javascript:;" onClick="MM_openBrWindow

I just don't understand where to terminate them... any help would be greatly appreciated! I have been struggling for hours...
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

The back slash is going before the quote, not after the equal. :) All quotes that are inside the string you want to print out will need to be "escaped" with the backslash. If you want a regular back-slash in your string you will need to slash it too.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php

echo "<a href="javascript:;" onClick="MM_openBrWindow('http://www.mydomain.com/path/path/','','width=200,height=473,top=15,left=15')"><img src="http://www.mydomain.com/path/path/unavailable.gif" 
border="0" alt="my alt text"></a>";

?>
It depends on how you're echoing. If you start your echo with ' you need to \ all the ' except for the closing one. If you're using " to start the echo, use \ behind ALL " except the closing ";
Any pro people correct me if im wrong here it appeared that way for me, and you just need to \ any of the "
So just look at what i gave you and use it as referance for next time, it's really simple, just learn to code \" instead of ", it didnt take me long to get into a habit of doing it, and it shouldnt for you either.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Also, if you're using an editor with syntax highlighting (ie it colors your code as you type, similar to what the PHP blocks on this forum do) you can check to see if your quotes are properly escaped. If you notice in Drachlen's example the entire echo is all the same color. If you didn't escape the quotes properly you would see the colors changing around a lot.

This is one of the reasons people like tools that do the syntax highlighting :)
th3monk3y
Forum Commoner
Posts: 29
Joined: Thu Jun 19, 2003 10:34 pm

Post by th3monk3y »

that's it!! You guys are Awesome thanks!

-Paul
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I would use:

Code: Select all

<?php
  echo "
?>
<a href="javascript:;" onClick="MM_openBrWindow('http://www.mydomain.com/path/path/','','width=200,height=473,top=15,left=15')"><img src="http://www.mydomain.com/path/path/unavailable.gif" 
border="0" alt="my alt text"></a>
<?php
  "; // ending the echo
?>
I find this way nice because there isn't a zillion slashes in your source and if you use Dreamweaver as an editor the code can be displayed in the WYSIWYG editor properly. ;)
Post Reply