[...]
It's just a simple script that asks the user to input their information, and confirm that the details provided are correct. [...]
Quote:
Originally Posted by Meta
Excellent, "break" worked a treat! Many thanks.
Any suggestions as to where to find some decent tutorials on using "while" loops? I don't just want to throw a messy script together and call it quits, I actually want to learn how to do this properly?
Appreciate the quick reply though.
Let me give you a few tasks that will help you experiment toward your goal as highlighted in read
Before you utilize any input validate it as something you were expecting. e.g.
How would you validate that the user have entered a proper gender? What if the user enters "Neutral" or any other variation of modern gender answers? What if it just pressed the ENTER/Return key?
How would you validate an age? What if the user enters 159 or 0 or just the ENTER/Return key?
How would you validate a name? Would you accept "Shakespeare's Hamlet" inputted as string for a name?
I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ......
Please help. Thx :confused: (3 Replies)
Hey all I'm working on a script that will scour a directory of 6000+ files for a line that at the end has a number.
Something like 'The number of outputs is: 39200'
I'm trying to devise a script to add all of these numbers up, so far I have the grep statement that pulls out each individual... (7 Replies)
. ./testFile.sh
url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv
wget $url$s1$suf;
sleep 10;
cat header.txt > $s1.txt;
chmod 777 $s1.txt;
sed '1d' table.csv?s\=$s1 >> $s1.txt;
rm -Rf table*
Very new at shell scripting as you can see... (3 Replies)
Hello there
Been using Unix bash scripting for two days now so am very new to this. I am currently doing a project now and i'm basically making a noughts and crosses game (or tic tac toe).
I have created the board using an array. When I try and check to see if the array is empty using an If... (3 Replies)
Hello,
I'm new to Sheel script and I need your help for a script I need to develop (for me).
Indead, I have a software which log all entry from internet and save it in text file.
But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
1. The problem statement, all variables and given/known data:
Arguments:
http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg
I am given these three arguments. $1, $2, $3
The first argument is the path to a directory.
So, how would I go into the directory and compare files?
I... (5 Replies)
Hi All,
I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder.
But... (5 Replies)
Hi All,
I am trying to monitor CPU load of few processes, with the same name.
The output that I get from top is the following
28171 root 20 0 1089m 21m 3608 S 103 0.3 15:16.89 /opt/ppp//h264rtptranscoder.bin --videoPort=14504 --audioPort=14505
27589 root 20 0 1060m 23m... (3 Replies)
Hi everyone,
i have the following script.sh:
foo='lsusb | grep Webcam | cut -c16-18'
sudo /home/user/public/usbreset /dev/bus/usb/001/$foo
when i try to call this script from python using subprocess.call("script.sh", shell=True) it seems that only 'sudo /home/user/public/usbreset' is being... (6 Replies)
Hi all
I have the folloing process that needs checking often:
ps -ef | grep ih
bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4
bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih
bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih
root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies
LEARN ABOUT PHP
http_build_query
HTTP_BUILD_QUERY(3) 1 HTTP_BUILD_QUERY(3)http_build_query - Generate URL-encoded query stringSYNOPSIS
string http_build_query PHP_QUERY_RFC1738 (mixed $query_data, [string $numeric_prefix], [string $arg_separator], [int $enc_type])
DESCRIPTION
Generates a URL-encoded query string from the associative (or indexed) array provided.
PARAMETERS
o $query_data
- May be an array or object containing properties. If $query_data is an array, it may be a simple one-dimensional structure, or
an array of arrays (which in turn may contain other arrays). If $query_data is an object, then only public properties will be
incorporated into the result.
o $numeric_prefix
- If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for ele-
ments in the base array only. This is meant to allow for legal variable names when the data is decoded by PHP or another CGI
application later on.
o $arg_separator
-arg_separator.output is used to separate arguments, unless this parameter is specified, and is then used.
o $enc_type
- By default, PHP_QUERY_RFC1738. If $enc_type is PHP_QUERY_RFC1738, then encoding is performed per RFC 1738 and the applica-
tion/x-www-form-urlencoded media type, which implies that spaces are encoded as plus ( +) signs. If $enc_type is
PHP_QUERY_RFC3986, then encoding is performed according to RFC 3986, and spaces will be percent encoded ( %20).
RETURN VALUES
Returns a URL-encoded string.
CHANGELOG
+--------+------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+------------------------------------------+
| 5.4.0 | |
| | |
| | The $enc_type parameter was added. |
| | |
| 5.1.3 | |
| | |
| | Square brackets are escaped. |
| | |
| 5.1.2 | |
| | |
| | The $arg_separator parameter was added. |
| | |
+--------+------------------------------------------+
EXAMPLES
Example #1
Simple usage of http_build_query(3)
<?php
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo http_build_query($data) . "
";
echo http_build_query($data, '', '&');
?>
The above example will output:
foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&baz=boom&cow=milk&php=hypertext+processor
Example #2
http_build_query(3) with numerically index elements.
<?php
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor');
echo http_build_query($data) . "
";
echo http_build_query($data, 'myvar_');
?>
The above example will output:
0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor
Example #3
http_build_query(3) with complex arrays
<?php
$data = array('user'=>array('name'=>'Bob Smith',
'age'=>47,
'sex'=>'M',
'dob'=>'5/12/1956'),
'pastimes'=>array('golf', 'opera', 'poker', 'rap'),
'children'=>array('bobby'=>array('age'=>12,
'sex'=>'M'),
'sally'=>array('age'=>8,
'sex'=>'F')),
'CEO');
echo http_build_query($data, 'flags_');
?>
this will output : (word wrapped for readability)
user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M&
user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&pastimes%5B1%5D=opera&
pastimes%5B2%5D=poker&pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12&
children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8&
children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO
Note
Only the numerically indexed element in the base array "CEO" received a prefix. The other numeric indices, found under pas-
times, do not require a string prefix to be legal variable names.
Example #4
Using http_build_query(3) with an object
<?php
class parentClass {
public $pub = 'publicParent';
protected $prot = 'protectedParent';
private $priv = 'privateParent';
public $pub_bar = Null;
protected $prot_bar = Null;
private $priv_bar = Null;
public function __construct(){
$this->pub_bar = new childClass();
$this->prot_bar = new childClass();
$this->priv_bar = new childClass();
}
}
class childClass {
public $pub = 'publicChild';
protected $prot = 'protectedChild';
private $priv = 'privateChild';
}
$parent = new parentClass();
echo http_build_query($parent);
?>
The above example will output:
pub=publicParent&pub_bar%5Bpub%5D=publicChild
SEE ALSO parse_str(3), parse_url(3), urlencode(3), array_walk(3).
PHP Documentation Group HTTP_BUILD_QUERY(3)