Saturday, January 29, 2011

WAMP and IIS

If both WAMP and IIS7 are installed, IIS7 will be displayed.

To solve this problem, do this:

To change WAMP,
click on WAMP Server icon on taskbar and go to Apache > httpd.conf

Change ‘Listen 80’ to ‘Listen 8080’ (As shown in the screenshot). Save and restart WAMP.


Reference:
http://www.programmerfish.com/how-to-run-wamp-server-parallel-with-iis-7-on-windows/

Now WAMP Server is accessible on http://localhost:8080/



Added Note:

With above change only, I have to manually enter 8080 to "http://localhost/"
I am going to edit the same file, "httpd.conf" file.


Original:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80


Changed:

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:8080


This did NOT do anything.
Put back the original setting.

Change it back to:Listen 80
(it was changed to "Listen 8080")
Then, DO this, instead!

Theory, you can have both, but IIS and Apache/Wamp are both web server and might conflict in some way, so you have to disable IIS in order for Wamp to work

Disable IIS in Vista:

Control Panel, Uninstall Programs, Turn Widows Features On or Off, uncheck Internet Information Services


In the I"Uninstall or Change Program" window, click "repair" icon, then uncheck "Internet Information Services".

Monday, January 24, 2011

visual studio 2010 C++ note

Problem: start without debugging missing in visual studio 2010 C++
When use ctrl-F5, it automatically closes console window.

To fix this, do the following:
  • right click the project name,
  • go to Properties page,
  • expand Configuration Properties -> Linker -> System,
  • select Console (/SUBSYSTEM:CONSOLE) in SubSystem dropdown.
There is no start without debugging icon, so only way to active it is ctrl-F5.

Friday, January 7, 2011

php - working with function (2)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Untitled</title>
</head>
<body>


<?php

//
// accept a list of email address,
// split address, add domain part to another array
//

function getUniqueDomains($list){
 $domains=array();
 foreach($list as $l){
  //
  // separate
xxx@yyy, and save arr[0]=xxx, arr[1]=yyy
  //

  $arr=explode("@", $l);
  //
  // save yyy into domain[]
  //

  $domains[]=trim($arr[1]); 
 }
 //
 // array_unique() removes duplicates elements
 //

 return array_unique($domains);
}


// read the file with email list
$fileContents=file("data.txt");

// pass the deliminated array
$returnedArray=getUniqueDomains($fileContents);

// print returned array
foreach($returnedArray as $d){
 print "$d<br />";
}


?>

</body>
</html>

php - working with function and sprintf()

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Untitled</title>
</head>
<body>

<?php

// define function
function getCircumference($radius){
 // return value 

 return (2*pi()*$radius);
}


//
// ex 1.
//


print "The answer is ".sprintf("%4.2f",getCircumference(20));
echo '<br />';


//
// ex 2.
//


$num=getCircumference(20);
$txtt='.';

$txt=sprintf("The answer is %4.2f%s", $num, $txtt);
echo $txt;
echo '<br />';


//
// ex 3.
//


// this prints
printf("printf: The answer is %4.2f%s", $num, $txtt);
echo '<br />';


// but, this does NOT print!!!
sprintf("sprintf: The answer is %4.2f%s", $num, $txtt);
echo '<br />';


?>
</body>
</html>

Thursday, January 6, 2011

php - working with files (4)

It reads a text file.
Make the first line title, and print.
Remove the line.
Using
nl1br(), converting text line breaker to the <br /> tag,
print the rest.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Untitled</title>
</head>
<body>

<?php

// read file
$data=file('C:\wamp\www\testFolder\tetsuro\tetsuroP04_php_file3\omelette.txt')
or die('Could not read file!');


/* first line is title. read it into variable */
$title=$data[0];

// remove first line from array
array_shift($data);
?>
 
<h2><?php echo $title; ?></h2>


<?php

//
// nl2br() function converts regular text linebreaks
// into the HTML equivalent, the <br /> tag.
//


/* iterate over content and print it */
foreach($data as $line){
 echo nl2br($line);
}

?>

</body>
</html>

php - working with files (3)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Untitled</title>
</head>
<body>


<?php

// if form has not yet been submitted,
// display input box

if(!isset($_POST['file'])){
?>
 <form action"<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
  Enter file path
  <input type="text" name="file">
 </form>
<?php
}


//else process from input
else{
 echo 'File name: <b>'.$_POST['file'].'</b><br />';
 /* check is file exist */

 if(file_exists($_POST['file'])){
  // print file size

  echo 'file size: '.filesize($_POST['file']).'byets. <br />';
  // print file owner 

  echo 'file owner: '.fileowner($_POST['file']).'<br />';
  // print file group 

  echo 'file group: '.filegroup($_POST['file']).'<br />';
  // print file permission 

  echo 'file permission: '.fileperms($_POST['file']).'<br />';
  // print file type 

  echo 'file type: '.filetype($_POST['file']).'<br />';
  // print last access time 

  echo 'file last accessed on: '
   .date('Y-m-d', fileatime($_POST['file'])).'<br />';
  // print last modification time 

  echo 'file last modified on '
   .date('Y-m-d', filemtime($_POST['file'])).'<br />';
  // is it directory? 

  if(is_dir($_POST['file'])){
   echo 'file is directory <br />';
  }
  // is it file? 

  if(is_file($_POST['file'])){
   echo 'file is a regular file <br />';
  }
  // is it a link? 

  if(is_link($_POST['file'])){
   echo 'file is a symbolic link <br />';
  }
  // is it executable? 

  if(is_executable($_POST['file'])){
   echo 'file is executable <br />';
  }
  // is it readable?

  if(is_readable($_POST['file'])){
   echo 'file is readable <br />';
  }
  // it is writable? 

  if(is_writable($_POST['file'])){
   echo 'file is writable <br />';
  }
 }
 else{
  echo 'file does not exist! <br />';
 }
}
?>

</body>
</html>

php - working with files (2)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Untitled</title>
</head>
<body>

<?php

/*
 * fopen() 

 */

// set file to write
$file = 'tmp/dump.txt';
echo "file opened: $file";
echo "<br />";


// open file
$fh = fopen($file, 'w') or die('Could not open file!');
echo "file opened, and fh returned: $fh";
echo "<br />";


// write to file
fwrite($fh, "Look, Ma, I wrote a file! ") or die('Could not write to file');
echo "finished writing.";
echo "<br />";


// close file
fclose($fh); 
echo "finished closing file";
echo "<br />";


/*
 * file_put_contents()
 */


// set file to write
$filename = 'tmp/dump.txt';

// write to file
file_put_contents($filename, "Look, Pa, I wrote a file! ") or die('Could not write to file');
echo "file opened, written, and closed: $file";
echo "<br />";

?>

</body>
</html>