473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem with spaces



this is the code:
print("change_text(\"english\",\"$myrow[word_english]\")>");

change_text(id,text) is a javascript function that changes some of the
text on the page to something else. $myrow[word_english] returns a
field from an entry in a mySQL database.

this works fine, rendering html like this:
change_text("english","green")>

unless $myrow[word_english] has a space in it, then I get this:
change_text("english","dark blue)>

what am I missing?
Thanks in advance! -jf

Jul 17 '05 #1
11 1660
I noticed that Message-ID:
<11*********************@g14g2000cwa.googlegroups. com> from
jf************@yahoo.com contained the following:
unless $myrow[word_english] has a space in it, then I get this:
change_text("english","dark blue)>

what am I missing?


Dunno, try:

print "change_text(\"english\",\"".$myrow['word_english']."\")>";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
nope, that gives me the exact same result. thx for trying, tho

Jul 17 '05 #3
> print("change_text(\"english\",\"$myrow[word_english]\")>");
Try this:

echo 'change_text( "english", "' . $myrow[ 'word_english' ] . '" )>';
Or check if $myrow[ 'word_english' ] value contains some special chars
at the end, which may influence print/echo.
Hilarion
Jul 17 '05 #4
(jf************@yahoo.com) decided we needed to hear...
this is the code:
print("change_text(\"english\",\"$myrow[word_english]\")>");

change_text(id,text) is a javascript function that changes some of the
text on the page to something else. $myrow[word_english] returns a
field from an entry in a mySQL database.

this works fine, rendering html like this:
change_text("english","green")>

unless $myrow[word_english] has a space in it, then I get this:
change_text("english","dark blue)>

what am I missing?
Thanks in advance! -jf


Maybe this is a bug in the PHP version you're using?
Your code works exactly as expected for me (PHPEd bundled PHP 4.3.4)
--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #5
nope, that's even worse... spaces are really the problem.
Here's the javascript text for the function I'm using, have I messed
something up here?

<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

Jul 17 '05 #6
J. Franchino wrote:
nope, that's even worse...
What do you mean by that?
spaces are really the problem.
That would be very strange.

Here's the javascript text for the function I'm using, have I messed
something up here?

<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>


Don't think so. If PHP output is messed up then it has nothing to do
with static (not generated) HTML (including JavaScript).
Try using echoing "var_export" on $myrow and on $myrow['word_english'] before your
"print" statement to check what is stored there and look at the HTML source which gets
generated.
Hilarion
Jul 17 '05 #7
okay, Hilarion, here's what I got (btw, thx again for helping):

$myrow gave me this:
array (
0 => '12',
'ID' => '12',
1 => '',
'word_japanese' => '',
2 => 'kon',
'word_romaji' => 'kon',
3 => 'dark blue',
'word_english' => 'dark blue',
4 => '',
'word_imageFN' => '',
5 => '',
'picture1' => '',
6 => '',
'picture2' => '',
7 => '',
'sound1' => '',
8 => '',
'sound2' => '',
9 => '',
'sound3' => '',
10 => '',
'sound4' => '',
11 => '1',
'step' => '1',
)

$myrow[word_english] gave me this:
'dark blue'

to me this offered no hints... does something look wrong to you?

Jul 17 '05 #8
I've got it down to this, but now it's not php, now I think it's a
javascript problem, but I still don't have it figured out... please
help!
<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

<div onclick=change_text("num1","word word")>click here</div>

Span: <b><span id="num1">num1</span></b>

Jul 17 '05 #9
> I've got it down to this, but now it's not php, now I think it's a
javascript problem, but I still don't have it figured out...

<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

<div onclick=change_text("num1","word word")>click here</div>

This "<div>" lacks quotes around "onclick" attribute value.

Try this:

echo '<div onclick="change_text( \'english\', \'' . $myrow[ 'word_english' ] . '\' )">click here</div>';

should output correct HTML/javascript:

<div onclick="change_text( 'english', 'dark blue' )">click here</div>
or this:

echo '<div onclick=\'change_text( "english", "' . $myrow[ 'word_english' ] . '" )\'>click here</div>';

should output (also correct):

<div onclick='change_text( "english", "dark blue" )'>click here</div>
or this:

echo '<div onclick="change_text( &quot;english&quot;, &quot;' . $myrow[ 'word_english' ] . '&quot; )">click here</div>';

which outputs (also correct):

<div onclick="change_text( &quot;english&quot;, &quot;dark blue&quot; )">click here</div>
You can also split the code to:

$onclick = 'change_text( "english", "' . $myrow[ 'word_english' ] . '" )';
echo '<div onclick="' . htmlspecialchars( $onclick ) . '">click here</div>';

which gives same HTML as one before, but is more readable in PHP.
Hilarion
Jul 17 '05 #10
Thanks for all your help, Hilarion. I've got it working now. I ended
up ditching the Javascript and going with this:

print("<font onClick=\"english.innerHTML='$myrow[word_english]'\">");

Jul 17 '05 #11
> Thanks for all your help, Hilarion. I've got it working now. I ended
up ditching the Javascript and going with this:

print("<font onClick=\"english.innerHTML='$myrow[word_english]'\">");

This still is JavaScript :) but I'm glad you solved the problem.
Hilarion
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oggdorf | last post by:
The table names in my database schema have spaces. When the .tab files are created in Visual Studio, the constraint names do not have brackets around them causing a syntax error. Is there a...
1
by: bob | last post by:
I have created a simple Windows service in VB.Net which installs fine using InstallUtil.exe to install it to, for example "c:\test", or "c:\Windows\YellowBanana", but if I install it to "c:\Program...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
1
by: Tim | last post by:
I ran into a problem with a script i was playing with to check code indents and need some direction. It seems to depend on if tabsize is set to 4 in editor and spaces and tabs indents are mixed on...
2
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
12
by: Vadim Guchenko | last post by:
Hello. I'm using the following code: <html> <head> <style type="text/css"> pre {display: inline;} </style> </head>
5
by: Raj | last post by:
Following is a code to replace blanks in entered string with adequate number of tabs & spacings as required. I've taken the width of tab as 5 characters here. The problem that occurs here is for...
5
by: NoOneCanHelpMe | last post by:
Hello everyone, could someone help me please, I want to print out the frequency of each vowel in the string and I think I will need to use the hash table I already have but im not sure how to do it...
1
by: moveitho | last post by:
Hi, I have the following script on my site but need to implement a select menu into the script as it would make it a lot tidier. This script adds the required amount of fields selected by the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.