PHP - Help Formating Output
I'm using system() to run NMAP and then display the output but it's one big string, how can I format it to look like what I see in the command line?
web app output: Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:44 CDT Interesting ports on localhost (127.0.0.1): Not shown: 993 closed ports PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 631/tcp open ipp 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds 0 command line output: Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:48 CDT Interesting ports on localhost (127.0.0.1): Not shown: 993 closed ports PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 631/tcp open ipp 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 0.45 seconds Code: [Select] <?php // path to NMAP $Path = '/usr/bin/nmap'; if(isset($_POST['scan'])) { $IP = $_POST['IP']; $ScanType = $_POST['ScanType']; echo "<br /><u>Results for NMAP Scan</u> <br />"; system("$Path $ScanType $IP 2>&1", $Output); echo $Output; } ?> any help would be greatly appreciated, thanks in advance!! Similar TutorialsHello i would like to as a little help on how to proper format an foreach output into an HTML table. I have a small function inside an class, that will retrieve the data of an MySQL table and return the result in 1 array, Outside that function i can get the values displayed i only need to format it to show in an table here's what i have: function that gets the data Code: [Select] function getfansub(){ $subfanarray = array(); $query = mysql_query("SELECT * FROM anr_fansub WHERE 1"); while($result = mysql_fetch_array($query)){ $subfanarray[] = $result; } return $subfanarray; } Outside the funtion/class Code: [Select] $fansubarray = $mysql->getfansub(); VAR_DUMP( $fansubarray ); echo "<br><br>"; foreach($fansubarray as $name){ echo $name['FansubID'] ." ". $name['Designation'] ." ". $name['Website'] ." ". $name['tracker'] ." ". $name['irc'] ."<br>"; } The problem i have with the formating (i really dont know who i can do it) is when he reaches the IRC link he needs to open and close the td and tr brakets of the table. any help or tip is apreciated, thanks in advance Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. I'm trying to figure out how to format a variable. I am listing the contents of a directory from an array and I trying to format the date field to be like - Jan 07, 2011 01:35 PM. When I try this format I get a 500 error message. <td width="'.$width_of_dates_column.'">'.$files("M d Y h:i:s A", filemtime['date'])[$key].'</td></tr>'; Is is possible to format the date after it's been put into the array or does it have to be done while it's being processed. Not sure if you need more code to determine the formatting. Please let me know if you do. Thank you. Hi Folks, I understand the basic math to accomplish what I want, at least I think I do I would like to confirm my logic and I need help with the final output format. I am coding a simple browser based, resource type of game. The gamer will select a certain item to produce another item and it will take x time to do it. Here is the basics of what I want, minus the coding to make it look pretty. How do I format $y to show HHH:MM:SS? Code: [Select] $complete = time() + $x; // To show how much time is remaining until completion or complete $y = $complete - time(); if $y > 0 { echo $y; } else { echo "complete"; } Looking for ideas and advise on this one. I want to take a 10 digit number and 1234567890 and format it like 132-456-7890 what would be my best bet as choice of methods to do this? Hi All, not able to understand I'm making miskate in CSS or PHP foreach statement. Need help with proper formating of the below code. I want to format the so that seasons divs will contain all the details about the episodes, title & plot. As of now season div is only wraping around the first episode only & ignoring remaining episodes details. Sorry I'm not able to explain this in words but if you access below code you will be able to understand. Code: [Select] <html> <head> <style type="text/css"> .main { width: 750px; margin-right: auto; margin-left: auto; background: #cc1; clear: both; overflow:auto; } .season { margin: 5px; padding: 5px; width: 730px; background: #960; } .details { overflow:hidden; } .ep, .title, .airdate, .plot { margin: 5px; padding: 5px; width: 675px; background: #CCC; } </style> </head> <body> <?php $eps = array( array( 'year' => '2005', 'eptitle' => 'title1', 'airdate' => 'Apr 24 2009', 'epplot' => 'plot of S01E01', 'season' => '1', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title2', 'airdate' => 'May 1 2009', 'epplot' => 'plot of S01E02', 'season' => '1', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title3', 'airdate' => 'May 8 2009', 'epplot' => 'plot of S02E01', 'season' => '2', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title4', 'airdate' => 'May 12 2009', 'epplot' => 'plot of S02E02', 'season' => '2', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title5', 'airdate' => 'May 15 2009', 'epplot' => 'plot of S03E01', 'season' => '3', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title6', 'airdate' => 'May 28 2009', 'epplot' => 'plot of S03E02', 'season' => '3', 'episode' => '2'), ); //var_dump($eps); $season = 0; echo "<div class='main'>"; foreach($eps as $k){ // season check start if($season!=$k['season']) { echo "<div class='season'><b>SEASON : </b>".$k['season']; } //season check finish echo "<div class='details'>"; echo "<div class='ep'><b>EPISODE : </b>".$k['episode']."</div>"; echo "<div class='title'><b>TITLE : </b>".$k['eptitle']."</div>"; echo "<div class='airdate'><b>AIRDATE : </b>".$k['airdate']."</div>"; echo "<div class='plot'><b>PLOT : </b>".$k['epplot']."</div>"; echo "</div>"; // season check start if($season!=$k['season']) { echo "</div>"; $season = $k['season']; } } echo "</div>"; ?> </body> </html> Hi! I'm working a on wordpress website with member pages. Members enter their information via custom fields. Everything is working great except when trying to create a link based on one of those custom field. Unless the member enter his website address in the http://mysite.com format the link my code create is not valid. This is the code i'm currently using Code: [Select] <?php $msite = get_post_meta($post->ID, 'ccio_site', true) ; if (!empty($msite)) { ?><li>Site Internet: <a href="<?php echo ($msite) ; ?>"><?php echo ($msite) ; ?></a></li><?php } ?> Example of a member page where the format create an error. The input field is: Code: [Select] www.pechabot.com Example of a member page where the format is ok. The input field is Code: [Select] http://www.annuairesgb.com How can I format the input string so my code will work even if someone doesn't write the full address with the http:? Thanks a lot for looking I have created an email template for HTML emails, but something isn't quite right. I use roundcube for my webmail and the email shows up perfect, but then in outlook it looks terrible. Gmail wont even receive it and in godaddy's webmail it is displayed at text with the <table> code written out. Any idea what I am missing? // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: <[mail]>' . "\r\n"; $headers .= 'From: cjkjckjxc <noreply@cojch.com>' . "\r\n"; $body = <<<BODY //stuff goes here BODY; So basically I have text which appears on an image. Code: [Select] $ability = "$title gets ability"; //Create Ability imagettfbbox(30, 0, $font, $ability); imagettftext($image, 30, 0, 70, 700, $fontcolor, $font, stripslashes($ability)); But the line of text is longer than the width of the area on the image it needs to fit in. How can I change this so it automatically starts a new line once it reaches the end of said area? how to format only one specific row based on the value of one cell in a row? $result = mysql_query(select bal, etc. etc ..query ) while($row = mysql_fetch_assoc($result)) echo "<tr>"; echo "<td>" . $row['Account'] . "</td>"; echo "<td>" . $row['licence'] . "</td>"; echo "<td>" . $row['own'] . "</td>"; echo "<td>" . $row['bal'] . "</td>"; echo "</tr>"; Would appreciate help on how to format only the $row['bal'] output to red colour IF bal >5000 Thanks Hey guys & gals, i have the following code: Code: [Select] <?php $date= $_SESSION['date']; echo $date; ?> Which is an echo of an earlier page: Code: [Select] <?php $_SESSION['date'] = date("c")?>; How do i format the echo of the first quote code? At present it echo's like so... Quote 2011-03-30T15:43:43+01:00 ...which although is useful for back office purposes, not so easy on the eye for the customer. How can i format so it's like DATE-MONTH-YEAR? I have googled this and there are examples, but none for when echoing a $_SESSION which is where i'm falling flat on my face. I tried this: but it doesn't work :-( Code: [Select] echo $startdate ("F j, Y") Thanks in advance to all who read and reply How to output a MySQL timestamp field to correct local time with daylight saving with PHP?
Local time is set in php.ini with: date.timezone = "Europe/London"
Confirmed set with: <?php echo date_default_timezone_get(); ?>
But when I echo the timestamp field it does not display correct UK time for the record (an hour behind correct UK time).
<?php echo date('jS F Y - g:ia', strtotime($row['Date'])); ?>
I have a function which is listing my directories w/ files (Images) in them. <?php function sortDirectory($path = 'images') { $ignore = array('.', '..', 'index.php'); $folder = array(); $dh = @opendir($path); while (false !== ( $file = readdir($dh) )) { if (!in_array($file, $ignore)) { if (is_dir("$path/$file")) { $folder[$file] = sortDirectory("$path/$file"); } else { $folder[$file] = "$path/$file"; } } } closedir($dh); ksort($folder); return $folder; } function getDirectory($folder = array(),$level = 0) { // Set which extensions should be approved in the XML file $extensions = array( 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF', 'bmp', 'BMP'); $spaces = str_repeat(' ', ( $level * 4)); foreach($folder as $file=>$path) { if (is_array($path)) { echo "<strong>$spaces $file</strong><br />"; getDirectory($path, $level+1); } else { if ( in_array( substr($file, -3), $extensions ) ){ echo "$spaces <a href=\"$path\">$file</a><br />"; } } } } getDirectory(sortDirectory()); ?> Im trying to get it to write an xml file in this fashion Code: [Select] <?xml version="1.0" encoding="utf-8" standalone="yes"?> <dir1> <pic> <image>file1.jpg</image> </pic> <pic> <image>file2.jpg</image> </pic> </dir1> <dir2> <pic> <image>file1.jpg</image> </pic> <pic> <image>file2.jpg</image> </pic> </dir2>but I cannot seem to get a grasp on this simplexml for more than 1 directory - any help appreciated.? Hey folks, I have made a cart for buying drinks. I also made an sql database. But when I click on the email button, I receive an email but only with the id of the products. I would like to have an output with the id of the product, but also the name of the product ( the name of the column in sql is also 'name') this is my code and you can check it out on http://fhcs.be/cart-demo3/ thanks in advance cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to bookshop...</a></p> <form action="mail.php" method="post"> <input type="submit" name="sendemail" value="Email" /> <input type="hidden" name="cart" value="<?= $cart; ?>" /> </form> </div> </body> </html> mail.php <?php session_start(); if($_POST['sendemail'] == 'Email') { $headers = 'From: Sender <andrej13@gmail.com>'; mail('andrej13@gmail.com', 'Subject', $_SESSION["cart"] , $headers); echo 'Your mail has been sent'; } else { echo 'message not sent'; } ?> and the functions.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$name.'</td>'; $output[] = '<td>€'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>€'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Hi, This script lists all the contents of the dir it is placed in bar itself. Perfect for what I need. However, I want to output the results as xml and being new to php I really don't know where to start. <?php foreach (new DirectoryIterator('.') as $file) { if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) { echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); } } ?> I'd be thankful for the help Thanks in advance. I don't have any output after I push the button :s I dont know how http://fhcs.be/index3.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions session_start(); ?> <?php if (!isset($_POST['submit'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <form method="post" action="<?php echo $PHP_SELF; ?>"> <input type="submit" value="Toon Output" name="submit"/> <?php $dranken=array() ; $DrinkResult=mysql_query("SELECT name,price FROM products")or die(mysql_error()); while($DrinkRow=mysql_fetch_assoc($DrinkResult)){ $dranken[] = $DrinkRow; } echo "<table>"; foreach ($dranken as $DrinkRow) { $optionlist = "<select name='{$DrinkRow['name']}_aantal'>"; for ($i=0;$i<10;++$i) { $optionlist .= "<option value='$i'>$i</option>"; } $optionlist .= "</select>"; echo "<tr><td>".$DrinkRow['name']." ".$DrinkRow['price']."</td>\n"; echo "<td>$optionlist</td></tr>\n"; } echo "</table>"; ?> </form> <?php } $dranken=array() ; $DrinkResult=mysql_query("SELECT name,price FROM products")or die(mysql_error()); while($DrinkRow=mysql_fetch_assoc($DrinkResult)){ $dranken[] = $DrinkRow; } echo "<table>"; $totaalPrijs = 0; foreach ($dranken as $DrinkRow) { $aantal = $_POST[$DrinkRow['name'] . "_aantal"]; if ($aantal > 0) { $prijsperDrank = $aantal * $DrinkRow['price']; echo $DrinkRow['name'] . " : " . $aantal . " Prijs: " . $prijsperDrank . "</br>"; $totaalPrijs=$totaalPrijs + $prijsperDrank; } } if($totaalPrijs>0){ echo " totaal: " .$totaalPrijs;} ?> </html> How do I got about outputing one row that can only hold one value? Any reason why the function below doesn't work? Code: [Select] <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins(){ $sql = 'SELECT * FROM account_info WHERE username ="' . $name .'"'; $result = mysql_query($sql); $wins = mysql_fetch_array($result); echo $wins['win']; } output_wins(); ?> Is there an easier way I can output this one row? Hello. I'm looking for some help to make a script. The script should run a .bat file, and get the output from it. (The text from the console). Regards Worqy the print_r($a)'s result is views_handle_field_node Object ( [view]=>view Object ( [db_table] => views_view [base_table] => node [args] => Array ( [0] => My entry 1 ) [use_ajax] => [result] => Array ( [0] => stdClass Object ( [nid] => 5 [node_title] => Title of a test entry [node_revisions_body] => [node_revisions_format] => 1 [node_vid] => 5 [term_data_name] => My first test term name [term_data_vid] => 1 [term_data_tid] => 1 [vocabulary_name] => Vocabulary 1 [node_revisions_vid] => 5 ) [1]=> stdClass Object ( [nid] => 8 [node_title] => Title of a test entry [node_revisions_body] => [node_revisions_format] => 1 [node_vid] => 5 [term_data_name] => My first test term name [term_data_vid] => 1 [term_data_tid] => 1 [vocabulary_name] => Vocabulary 1 [node_revisions_vid] => 5 .. [2].. .. now i want to output the [nid]=>5 and[nid]=>8.....and all the nid's value.i use this, but can't work. $views_handle_field_node->$view->$result[]->nid. what's the correct output of it. hello guys..!!! am new to this phpfreak community...i hav faced some problem while getting on floating point nos addition..if i use echo (int)((0.1+0.7))*10; i am getting output as 7. If i remove (int), i would get output as 8..which is correct... for any other possibilities like ((0.1+0.2))*10 am getting correct output as 3..pls guys help me on this wid proper reason....waiting for solution.... |