473,386 Members | 1,654 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,386 software developers and data experts.

Strange String and URL Problems

Hey, I've got some code here that puzzles me. I'm putting together a
url based on user input. Should be pretty straightforward, but there's
a problem. First, here's my code.

---

$myurl="write.php?T1=" . $_GET["T1"] . "&T2=" . $_GET["T2"] . "&T3=" .
$_GET["T3"] . "&T4=" . $_GET["T4"] . "&T56=" . $_GET["T56"] . "&T7=" .
$_GET["T7"] . "&T89=" . $_GET["T89"] . "&T10=" . $_GET["T10"] . "&T11="
.. $_GET["T11"];

echo $myurl;
echo "<a href=\"" . $myurl . ">OK - Next Step &gt;&gt;" .
"</a>";

---
** Please note that the 3 lines with the $_GET variables are really on
1 line.

So, that makes my link fine. The problem is my output:

write.php?T1=Word1
Word2

It takes spaces in the $_GET["T1"] and for some reason makes them into
new lines....... which throws off my url completly because it's then
sending you to write.php?T1=Word1, dropping word2 and the rest of the
get variables.

Why is this??

Please help. Sorry if this wasn't clear, but it's a bit confusing, and
I'll try to clarify it if you need more.

Thanks,
iw****@gmail.com

Aug 19 '05 #1
8 1484
Sorry, but I have a few corrections. I meant "4" lines instead of 3,
and it DOESN'T make my line fine.

Aug 19 '05 #2
IW****@gmail.com wrote in news:1124478378.973496.290910
@z14g2000cwz.googlegroups.com:
Hey, I've got some code here that puzzles me. I'm putting together a
url based on user input. Should be pretty straightforward, but there's
a problem. First, here's my code.

---

$myurl="write.php?T1=" . $_GET["T1"] . "&T2=" . $_GET["T2"] . "&T3=" .
$_GET["T3"] . "&T4=" . $_GET["T4"] . "&T56=" . $_GET["T56"] . "&T7=" .
$_GET["T7"] . "&T89=" . $_GET["T89"] . "&T10=" . $_GET["T10"] . "&T11="
. $_GET["T11"];

Format your string using urlencode():

$tmpa = array();
foreach ($idx in array('T1','T2','T3','T4','T56','T7','T89','T10'))
$tmpa[] = $idx . '=' . urlencode($_GET[$idx]);
$myurl = 'write.php?' . implode('&',$tmpa);

You'll notice I changed the way the code creates the URL. By using the
foreach() construct, you can easily change what indices you use.
echo $myurl;
echo "<a href=\"" . $myurl . ">OK - Next Step &gt;&gt;" .
"</a>";


echo '<a href="' . $myurl . '">OK - Next Step &gt;&gt;</a>';

See if that helps.

Ken
Aug 19 '05 #3
That looks great to me, but when I run it, I get a

Parse error: syntax error, unexpected T_STRING in C:\Program
Files\Apache Group\Apache2\htdocs\schedule\confirm.php on line 48.

Line 48 is foreach ($idx in
array('T1','T2','T3','T4','T56','T7','T89','T10')) .

But I don't see a problem... Commenting out the code you gave resolves
the error...

Thanks,
iw****@gmail.com

Aug 19 '05 #4
IW****@gmail.com wrote in news:1124480293.949505.8120
@f14g2000cwb.googlegroups.com:
That looks great to me, but when I run it, I get a

Parse error: syntax error, unexpected T_STRING in C:\Program
Files\Apache Group\Apache2\htdocs\schedule\confirm.php on line 48.

Line 48 is foreach ($idx in
array('T1','T2','T3','T4','T56','T7','T89','T10')) .


Can you post the lines before line 48. Sometimes the error is actually on a
preceding line and PHP doesn't realize it until something doesn't make
sense.

Ken
Aug 19 '05 #5
<?php

$tmpa = array();
foreach ($idx in array('T1','T2','T3','T4','T56','T7','T89','T10')) {
$tmpa[] = $idx . '=' . urlencode($_GET[$idx]);
}
$myurl = 'write.php?' . implode('&',$tmpa);
echo $myurl;

echo '<a href="' . $myurl . '">OK - Next Step &gt;&gt;</a>';

?>

That's the only php in this document...

Sorry for being a pest

iw****@gmail.com

Aug 19 '05 #6
Oh, I tried adding the { }'s after it didn't work the first time,
because the php manual uses them, but they didn't help.

Aug 19 '05 #7
IW****@gmail.com wrote in news:1124481301.015505.79180
@g49g2000cwa.googlegroups.com:
<?php

$tmpa = array();
foreach ($idx in array('T1','T2','T3','T4','T56','T7','T89','T10')) {
My error (that's what I get for not checking my code...)
The foreach line should read:

foreach (array('T1','T2','T3','T4','T56','T7','T89','T10') as $idx)
$tmpa[] = $idx . '=' . urlencode($_GET[$idx]);
}
$myurl = 'write.php?' . implode('&',$tmpa);
echo $myurl;

echo '<a href="' . $myurl . '">OK - Next Step &gt;&gt;</a>';

?>

That's the only php in this document...

Sorry for being a pest


Not a problem. How else would you learn...

Ken
Aug 19 '05 #8
Works like a charm, thanks for your patience!

Thanks,
iw****@gmail.com

Aug 19 '05 #9

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

Similar topics

1
by: ksedran | last post by:
Hi All, I am seeing a very strange issue with a winform I have. There are a few statements in the code, that at one point were working just fine. I had compiled the code a few days ago and...
2
by: Tony Johansson | last post by:
Hello! I have two very small classes(Head_1 and Head_2) see below and a very small main. I have run into a very strange problem. This program doesn't compile but if I replace the string...
1
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
2
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
2
by: Buddy Ackerman | last post by:
I have a web app that I have setup on numerous web servers. I've set one up for a new client at their hosting facility and cannot get it to connect to their database. I get a "SQL Server does not...
8
by: WhiteWizard | last post by:
Have we got a STRANGE one going here. We converted from 1.1 to 2.0 about 2 weeks ago and this has been a problem since then...but only on SOME machines in our development group. The application...
3
by: TheSteph | last post by:
Hi, I have a small serializable struct : public struct TestStruct { public string Title; public int Age; public string Name;
8
by: FBM | last post by:
Hi there, I am puzzled with the behavior of my code.. I am working on a networking stuff, and debugging with eclipse (GNU gdb 6.6-debian).. The problem I am experiencing is the following: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.