View Subcategory
Output a string to the console
Write the string
"Hello World!" to STDOUT
haskell
main = putStrLn "Hello World!"
Retrieve a string containing ampersands from the variables in a url
My PHP script first does a query to obtain customer info for a form. The form has first name and last name fields among others. The customer has put entries such as
The script variable for first name $_REQUEST
I have tried various functions like urldecode but all to no avail. I even tried encoding the url before the view screen is painted so that the url looks like
Of course this fails for the same reasons. What is a better approach?
"Ron & Jean" in the first name field in the database. Then the edit form script is called with variables such as
"http://myserver.com/custinfo/edit.php?mode=view&fname=Ron & Jean&lname=Smith".
The script variable for first name $_REQUEST
['firstname'] never gets beyond the "Ron" value because of the ampersand in the data.
I have tried various functions like urldecode but all to no avail. I even tried encoding the url before the view screen is painted so that the url looks like
"http://myserver/custinfo/edit.php?mode=view&fname="Ronxxnbsp;xxamp;xxnbsp;Jean"&lname=SMITH". (sorry I had to add the xx to replace the ampersand or it didn't display meaningful url contents the browser sees.)
Of course this fails for the same reasons. What is a better approach?
haskell
import Network.CGI
query = "http://myserver.com/custinfo/edit.php?" ++ formEncode [("mode", "view"), ("fname", "Ron & Jan"), ("lname","Smith")]
query = "http://myserver.com/custinfo/edit.php?" ++ formEncode [("mode", "view"), ("fname", "Ron & Jan"), ("lname","Smith")]
string-wrap
Wrap the string
Expected output:
> The quick brown fox jumps over the lazy dog. The quick brown fox jumps over t
> he lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
> jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The qui
> ck brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy
> dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps o
> ver the lazy dog. The quick brown fox jumps over the lazy dog.
"The quick brown fox jumps over the lazy dog. " repeated ten times to a max width of 78 chars, starting each line with "> "
Expected output:
> The quick brown fox jumps over the lazy dog. The quick brown fox jumps over t
> he lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
> jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The qui
> ck brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy
> dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps o
> ver the lazy dog. The quick brown fox jumps over the lazy dog.
haskell
wrap str
| length str <= 77 = [str]
| otherwise = [take 77 str] ++ wrap (drop 77 str)
mapM_ putStrLn . map ("> " ++) . wrap . concat . replicate 10 $ "The quick brown fox jumps over the lazy dog. "
| length str <= 77 = [str]
| otherwise = [take 77 str] ++ wrap (drop 77 str)
mapM_ putStrLn . map ("> " ++) . wrap . concat . replicate 10 $ "The quick brown fox jumps over the lazy dog. "
