MyBB Community Forums

Full Version: need some help with PHP and JS
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Not sure if this is the right place to post this, but i know there are some php guru's here, so :p
It like this: I have a page written 99% in php (everything with Print "" etc.)
and I would like to use a javascript for tooltips in my page.
I have this:

print "<tr class='mainrow'><td><b>Honor: $mydb[land]</b></td></tr>";

And I need to replace Honor with this:

<span class="tip"
onmouseover="tooltip('this is what the tooltip will be');"
onmouseout="exit();">Honor</span>

But I have a problem with the ' located here:

tooltip('this is what the tooltip will be')

It's hard to explain but people who know php understand the code1="code2='code3=??'" thing Toungue How do I solve that? I tried to define tooltip('this is what the tooltip will be'); as a variable but that didn't work out...
You need to parse the " if you use " before it all.
print "<tr class=\"mainrow\"><td><b><span class=\"tip\"
onmouseover=\"tooltip('this is what the tooltip will be');\"
onmouseout=\"exit();\">Honor</span>: $mydb['land']</b></td></tr>";
What do you mean by this? -> code1="code2='code3=??'"
that u use " to define a code and ' to define a code within a code but there's no third thing Smile
Yes there is, you need to parse the quotes with \, you don't need to use ' inside " you can use \"
The code I wrote above will work.

And then you have another choice aswell.
echo <<<END
<tr class="mainrow"><td><b><span class="tip"
onmouseover="tooltip('this is what the tooltip will be');"
onmouseout="exit();">Honor</span>: $mydb['land']</b></td></tr>
END; 
what's the <<<END thing?
Looking at the code, i think it means "echo" content between <<<END and END;

Because the content isn't between " it removes the need to escape " in the code that is been echoed.

If it does what i think it does, thats damn cool and i didnt know you could do that.
That is exactly what it means - and if you look in the MyBB installer we also make good use of it echo <<<END and END;

Chris
Yes that's correct what MrDoom said.
It's an good way todo long codes, it looks bad in syntaxhighlighter though Toungue
Just remember, these gotta be on an own line.
so
echo <<<END hiya there END;
won't work Smile

This will also work with the print function.
It's called "heredoc" syntax. It's only mentioned in the PHP manual very briefly, which is likely why you've never seen it before.

CraKteR Wrote:Just remember, these gotta be on an own line.

Their own line, and with no whitespace either.

echo <<<END
hiya there
	END;

will also not work (there's whitespace before "END;"). This tripped me up a few times.

All-caps END is used by convention, but you can use any string and/or letter-case you want, which can be helpful for describing what you're echoing.
sunspark Wrote:It's only mentioned in the PHP manual very briefly, which is likely why you've never seen it before.
Reminds me of using
../
to go up a level in links, its never mentioned anywhere and when i saw it used it some code i had to ask what it was. Now i have it committed to memory.

Why do very useful and simple things get very little easily accessible information of them, seems strange.
Pages: 1 2