Page 1 of 1
Crazy Quote/Apostrophe Situation
Posted: Wed Nov 26, 2008 3:05 pm
by modchamp
Well my brain is utterly fried right now and I need a little help.
Code: Select all
$linkd = "<a href=\'$address" . "upload/$ran1" . $ran2 . "$_FILES['file']['name']\\'>"
echo "<br>HTML Link (for websites): " . "<input readonly='readonly' type=text value=$linkd>";
I'm basically trying to get a readonly text field that will display the users uploaded image location in <a href> form, kind of similar to imageshack.us
Thanks in advance,
modchamp
Edit: Guess I should explain my problem better. The text in the box is cutting off right at the apostrophe, check below for my updated code.
Re: Crazy Quote/Apostrophe Situation
Posted: Wed Nov 26, 2008 6:19 pm
by modchamp
I've edited to the following:
Code: Select all
$linkd = "<a href='$address" . "upload/" . $ran1 . $ran2 . $_FILES['file']['name'] . "\'>";
echo "<br>HTML Link (for websites): " . "<input readonly='readonly' type=text value=$linkd>";
Now I get <a in the textbox and then > after it. Any ideas?
Re: Crazy Quote/Apostrophe Situation
Posted: Wed Nov 26, 2008 7:21 pm
by requinix
You need quotes around the attributes. Like how you did with the a's href and the input's readonly.
Code: Select all
<a href="link"><br>HTML Link (for websites): <input type="text" readonly="readonly" value="value">
In case the link and the value have quotes or apostrophes you should use
htmlentities to make them safe (you'll need the ENT_QUOTES flag if you use apostrophes around the value instead of quotes).
Using quotes/apostrophes and htmlentities will fix your other problem too.
Re: Crazy Quote/Apostrophe Situation
Posted: Wed Nov 26, 2008 8:10 pm
by modchamp
Not quite sure how you meant me to use the htmlentities but here's what I did:
Code: Select all
$linkd = "<a href='$address" . "upload/" . $ran1 . $ran2 . $_FILES['file']['name'] . "'\>";
$linkx = htmlentities($linkd);
echo "<br>Test: " . $linkx;
echo "<br>HTML Link (for websites): " . "<input readonly='readonly' type=text value=$linkx";
And this outputs:

Re: Crazy Quote/Apostrophe Situation
Posted: Wed Nov 26, 2008 11:17 pm
by requinix
I don't even know what you're doing now... feels like you're just throwing functions at your problem and hoping they will solve it.
That link... is it supposed to be clickable? Or is it text for the person to use?
Okay. Anything you put into htmlentities will NOT work as HTML. It'll be displayed instead of interpreted. This is good if you
don't want HTML to work. If you
do then don't use it.
If you put stuff into a tag, like in an attribute, you need htmlentities (or htmlspecialchars - besides the point) to make it safe. But you also need to put the value in quotation marks or apostrophes.
Code: Select all
<input type="text" value=<?php echo $html; ?>> -- BAD
<input type="text" value="<?php echo $html; ?>"> -- BAD
<input type="text" value=<?php echo htmlentities($html); ?>> -- BAD
<input type="text" value="<?php echo htmlentities($html); ?>"> -- GOOD
ALSO GOOD:
<input type='text' value='<?php echo htmlentities($html, ENT_QUOTES); ?>'>
Oh, and when you want to post another picture, don't. Just post part of the HTML source of the page. That whole "pictures are worth a thousand words" is total BS.
Re: Crazy Quote/Apostrophe Situation
Posted: Thu Nov 27, 2008 8:16 am
by modchamp
Yes it's supposed to be clickable.
As you can see in that textbox it just has <a whereas I want it to have everything that $linkx has. I want the full link that is after Test: to go into the HTML Links (for websites) text box.