Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get quotes in inputs to preload

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
I'm trying to preload xhtml inputs with values from database that include double and single quotes (as inch and foot)

Code:
while ($tbl = $sth->fetchrow_arrayref)
	{
	$tbl10 = "<option value=\"@$tbl\">@$tbl</option>";
	if ($tbl10 =~ m/($vendor_name)/) {
	$tbl10 =~ s/<option value/<option selected="selected" value/;
	}
	$tbl10 =~ s/&/&amp;/g;
print "$tbl10";
}

I have tried using
Code:
$tbl10 =~ s/"/&quot;/g;
doesn't work, tried some other substitutions, but they all fail to do anything.

Code:
$tbl10 =~ s/&/&amp;/g;
above works fine.

But I keep getting double quotes in xhtml, which screws up value that I want correctly preloaded in update form.
 
Whats in $tbl10? If there are double-quotes your regexp should work.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I'm afraid I found a bug in me, not the program.
What I was doing was working fine, just in the wrong spot!
I moved it and everything OK, now
 
It's probably worth having a subroutine to escape all the XML 'specials', (&amp;, &quot;, &apos;, &gt;, and &lt;) in your data. Remember to do &amp first, otherwise you will get strange results. There is probably a module that will do it on CPAN, but as it's only five lines of code it's up to you...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I got the others, I overlooked &gt; and &lt;
I will add those.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top