Professional Documents
Culture Documents
Line in PHP?
If you are using fgets() to read a line from a text file, you may want to use
the chop() function to remove the new line character from the end of the line
as shown in this PHP script:
<?php
$handle = fopen("/tmp/inputfile.txt", "r");
while ($line=fgets()) {
$line = chop($line);
# process $line here...
}
fclose($handle);
?>
To find a substring in a given string, you can use the strpos() function. If you
call strpos($haystack, $needle), it will try to find the position of the first
occurrence of the $needle string in the $haystack string. If found, it will
return a non-negative integer represents the position of $needle. Othewise, it
will return a Boolean false. Here is a PHP script example of strpos():
<?php
$haystack1 = "2349534134345globalguideline16504381640386488129";
$haystack2 = "globalguideline234953413434516504381640386488129";
$haystack3 = "guideline234953413434516504381640386488129ggl";
$pos1 = strpos($haystack1, "globalguideline");
$pos2 = strpos($haystack2, "globalguideline");
$pos3 = strpos($haystack3, "globalguideline");
print("pos1 = ($pos1); type is " . gettype($pos1) . "\n");
print("pos2 = ($pos2); type is " . gettype($pos2) . "\n");
print("pos3 = ($pos3); type is " . gettype($pos3) . "\n");
?>
If you are developing a Web application that uses PHP and needs to access
MS SQL Server, you should go download and install PHP to your local
machine to practice PHP and SQL Server connection. The best way to
download and install PHP on Windows systems is to:
If you know the position of a substring in a given string, you can replace that
substring by another string by using the substr_replace() function. Here is a
PHP script on how to use substr_replace():
<?php
$string = "Warning: System will shutdown in NN minutes!";
$pos = strpos($string, "NN");
print(substr_replace($string, "15", $pos, 2)."\n");
sleep(10*60);
print(substr_replace($string, "5", $pos, 2)."\n");
?>
9. What is the maximum size of a file that can be uploaded using PHP
and how can we change this?
Ans: By default the maximum size is 2MB. and we can change the following
setup at php.iniupload_max_filesize = 2M
12. Shopping cart online validation i.e. how can we configure Paypal, etc.?
ans : first w ehave to create a test marchentaccount in paypal to
use that in test mode
<form name="xxx"
action="https://www.sandbox.paypal.com/cgi-bin/webscr"
method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo
$MARCHENT_ID;?>">
<input type="hidden" name="item_name" value="<?php echo
$ORDER_REQUEST;?>">
<input type="hidden" name="item_number" value="5">
<input type="hidden" name="<?php echo $item_name;?>"
value="<?php echo $rst['title'];?>">
<input type="hidden" name="<?php echo $amount;?>"
value="<?php echo $rate*$rst['cost'];?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="return" value="<?php echo
$RETURN_ADDRESS;?>">
<input type="hidden" name="cpp_header_image" value="<?php
echo $HEADERIMAGE;?>">
<input type="hidden" name="cancel_return" value="<?php echo
$CANCEL_RETURN;?>">
</form>
<script>
document.xxx.submit();
</script>
we are using
<script>
document.xxx.submit();
</script>
13. How can we encrypt and decrypt a data present in a mysql table using
mysql?
14. How can we encrypt the username and password using PHP?
1) set_time_limit() function
2) ini_set() function
16. How can we take a backup of a mysql table and how can we restore it.?
Restore of a table:
click on phpmyadmin -> open the database ->click on import button -> and
select the file location -> and click on go button.
17. How can we optimize or increase the speed of a mysql select query?
Ans: For increase speed of select query. There are some factor like...
-By using Limit in query
-By using Index on table
-By using Primary key
18. What is the PHP predefined variable that tells the What types of images
that PHP supports?
19. List out some tools through which we can draw E-R diagrams for mysql.
20. How can I retrieve values from one database server and store them in
other database server using PHP?
$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
$db2 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);At this point you can only
fetch records from you previous ResultSet,
i.e $res1 - But you cannot execute new query in $db1, even
if you supply the link as because the link was overwritten
by the new db.so at this point the following script will fail
$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
22.
ans.