Re: [PHP] preg_replace question
Am 24.01.2011 18:08, schrieb Alex Nikitin: If you declare your arrays, and set k to 0 first, put quotes around array values and use the correct limit (you can default to -1), you will get results, here is code and example (hopefully this helps you) ?php function internal_links($str, $links, $limit=-1) { $pattern=array(); $replace=array(); $k=0; foreach($links AS $link){ $pattern[$k] = ~\b({$link['phrase']})\b~i; $replace[$k] = 'a href='.$link['link'].'\\1/a'; $k++; } return preg_replace($pattern,$replace,$str, $limit); } echo internal_links(süße knuffige Beagle Welpen ab sofort, array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)), -1); Output: süße knuffigea href=http://google.com;Beagle/a a href= http://wolframalpha.com;Welpen/a ab ~Alex Hello, thank you all for your help. It seems that I am building the array wrong. Your code works with that array: $internal_links = array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)); I am pulling the data out of a DB and am using this code: while ($row = mysql_fetch_object($result)){ $internal_links[$row-ID]['phrase'] = $row-phrase; $internal_links[$row-ID]['link'] = $row-link; } You build the array different, could you help me to adapt this on my code? I tried $internal_links['phrase'][] as well, but that did not help either. Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace question
Am 25.01.2011 12:31, schrieb Merlin Morgenstern: Am 24.01.2011 18:08, schrieb Alex Nikitin: If you declare your arrays, and set k to 0 first, put quotes around array values and use the correct limit (you can default to -1), you will get results, here is code and example (hopefully this helps you) ?php function internal_links($str, $links, $limit=-1) { $pattern=array(); $replace=array(); $k=0; foreach($links AS $link){ $pattern[$k] = ~\b({$link['phrase']})\b~i; $replace[$k] = 'a href='.$link['link'].'\\1/a'; $k++; } return preg_replace($pattern,$replace,$str, $limit); } echo internal_links(süße knuffige Beagle Welpen ab sofort, array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)), -1); Output: süße knuffigea href=http://google.com;Beagle/a a href= http://wolframalpha.com;Welpen/a ab ~Alex Hello, thank you all for your help. It seems that I am building the array wrong. Your code works with that array: $internal_links = array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)); I am pulling the data out of a DB and am using this code: while ($row = mysql_fetch_object($result)){ $internal_links[$row-ID]['phrase'] = $row-phrase; $internal_links[$row-ID]['link'] = $row-link; } You build the array different, could you help me to adapt this on my code? I tried $internal_links['phrase'][] as well, but that did not help either. Thank you for any help, Merlin HI Again :-) the building of my array seems fine. Here is what goes wrong: If you use this array: $internal_links = array(array('phrase'=Beagle Welpen, 'link'=http://wolframalpha.com;), array('phrase'=Welpen, 'link'=http://google.com;)); Then it will fail as well. This is because the function will replace Beagle Welpen with the hyperlink and after that replace the word welpen inside the hyperlink again with a hyperlink. Is there a function which will not start looking for the words at the beginnning of the text for each replacement, but simply continue where it did the last replacement? Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace question
On 25 January 2011 12:04, Merlin Morgenstern merli...@fastmail.fm wrote: Am 25.01.2011 12:31, schrieb Merlin Morgenstern: Am 24.01.2011 18:08, schrieb Alex Nikitin: If you declare your arrays, and set k to 0 first, put quotes around array values and use the correct limit (you can default to -1), you will get results, here is code and example (hopefully this helps you) ?php function internal_links($str, $links, $limit=-1) { $pattern=array(); $replace=array(); $k=0; foreach($links AS $link){ $pattern[$k] = ~\b({$link['phrase']})\b~i; $replace[$k] = 'a href='.$link['link'].'\\1/a'; $k++; } return preg_replace($pattern,$replace,$str, $limit); } echo internal_links(süße knuffige Beagle Welpen ab sofort, array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)), -1); Output: süße knuffigea href=http://google.com;Beagle/a a href= http://wolframalpha.com;Welpen/a ab ~Alex Hello, thank you all for your help. It seems that I am building the array wrong. Your code works with that array: $internal_links = array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)); I am pulling the data out of a DB and am using this code: while ($row = mysql_fetch_object($result)){ $internal_links[$row-ID]['phrase'] = $row-phrase; $internal_links[$row-ID]['link'] = $row-link; } You build the array different, could you help me to adapt this on my code? I tried $internal_links['phrase'][] as well, but that did not help either. Thank you for any help, Merlin HI Again :-) the building of my array seems fine. Here is what goes wrong: If you use this array: $internal_links = array(array('phrase'=Beagle Welpen, 'link'=http://wolframalpha.com;), array('phrase'=Welpen, 'link'=http://google.com;)); Then it will fail as well. This is because the function will replace Beagle Welpen with the hyperlink and after that replace the word welpen inside the hyperlink again with a hyperlink. Is there a function which will not start looking for the words at the beginnning of the text for each replacement, but simply continue where it did the last replacement? Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The solution I've used in the past for this sort of issue (recursive replacements when not wanted) is to replace each known part with a unique placeholder. Once the initial data has been analysed and the placeholders are in place, then replace the placeholders with the correct value. So, rather than ... $internal_links = array ( array('phrase'=Beagle Welpen, 'link'=http://wolframalpha.com;), array('phrase'=Welpen, 'link'=http://google.com;) ); Use ... $internal_links = array ( array('phrase'='Beagle Welpen', 'link'='_RAQ_TAG_1_'), array('phrase'='Welpen','link'='_RAQ_TAG_2_'), array('phrase'='_RAQ_TAG_1_''link'='http://wolframalpha.com'), array('phrase'='_RAQ_TAG_2_''link'='http://google.com'), ); By keeping them in the above order, each phrase will be replaced in the same way. Obviously, if your text includes _RAQ_TAG_1_ or _RAQ_TAG_2_ then you will have to use more appropriate tags. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace question
$internal_links=array(); I prefer to init arrays, it also avoids unnecessary notices, and sometimes weird results, but either one of those while loops should make the desired array while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { array_push($internal_links, array('phrase'=$row['phrase'], 'link'=$row['link'])); } or while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $internal_links[] = array('phrase'=$row['phrase'], 'link'=$row['link']); } or while($row = mysql_fetch_object($result)) { $internal_links[] = array('phrase'=$row-phrase, 'link'=$row-link); } (you can figure out how to do it with array_push if you choose to, but you get the general idea) ~ Alex On Jan 25, 2011 6:35 AM, Merlin Morgenstern merli...@fastmail.fm wrote: Am 24.01.2011 18:08, schrieb Alex Nikitin: If you declare your arrays, and set k to 0 first, put quotes around array values and use the correct limit (you can default to -1), you will get results, here is code and example (hopefully this helps you) ?php function internal_links($str, $links, $limit=-1) { $pattern=array(); $replace=array(); $k=0; foreach($links AS $link){ $pattern[$k] = ~\b({$link['phrase']})\b~i; $replace[$k] = 'a href='.$link['link'].'\\1/a'; $k++; } return preg_replace($pattern,$replace,$str, $limit); } echo internal_links(süße knuffige Beagle Welpen ab sofort, array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)), -1); Output: süße knuffigea href=http://google.com;Beagle/a a href= http://wolframalpha.com;Welpen/a ab ~Alex Hello, thank you all for your help. It seems that I am building the array wrong. Your code works with that array: $internal_links = array(array('phrase'=beagle, 'link'=http://google.com;),array('phrase'=welpen, 'link'=http://wolframalpha.com;)); I am pulling the data out of a DB and am using this code: while ($row = mysql_fetch_object($result)){ $internal_links[$row-ID]['phrase'] = $row-phrase; $internal_links[$row-ID]['link'] = $row-link; } You build the array different, could you help me to adapt this on my code? I tried $internal_links['phrase'][] as well, but that did not help either. Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [security] PHP has DoS vuln with large decimal points
hi, On Mon, Jan 17, 2011 at 5:21 AM, Tommy Pham tommy...@gmail.com wrote: Thanks Dan. I'll keep it in mind for the future. For interested parties, that's found in the official Windows 5.3.3 NTS VC9 build. Works fine with the current official 5.3.5 NTS VC9. 5.3.5 was released only to fix this exact bug :-) Cheers, -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Installing PEAR
Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On 01/25/2011 11:25 AM, Nilesh Govindarajan wrote: On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. Yes, I'm on Ubuntu and just used 'apt-get install php-pear'. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
Am 25.01.2011 18:25, schrieb Nilesh Govindarajan: On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. Hi Ethan, erm, on linux you could just install it with apt/aptitude !? e.g. aptitude install php5-pear after installing that package you could simply type pear at your shell and install pear packages or what ever you want to do with it ;) Regards, Ronny -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On Tue, Jan 25, 2011 at 13:43, Ronny Tiebel ronny.tie...@qumido.de wrote: erm, on linux you could just install it with apt/aptitude !? 's/linux/Ubuntu or Debian as root' -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
(sorry for top post) As he mentioned using lynx ( and I'm assuming the OS rather than the browser here, as I'm not aware of the browser having those sorts of capabilities) then could it be that all the pear packages don't exist? Mostly, pear packages can just be copied into your app directories or in an include path that apache is aware of and things will just work, so that might be a viable solution if the repositories don't work out. Thanks, Ash http://www.ashleysheridan.co.uk - Reply message - From: Shawn McKenzie nos...@mckenzies.net Date: Tue, Jan 25, 2011 18:44 Subject: [PHP] Installing PEAR To: Nilesh Govindarajan nil...@itech7.com Cc: php-general@lists.php.net On 01/25/2011 11:25 AM, Nilesh Govindarajan wrote: On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. Yes, I'm on Ubuntu and just used 'apt-get install php-pear'. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On Tue, Jan 25, 2011 at 13:54, Ronny Tiebel ronny.tie...@qumido.de wrote: ubuntu (10.10) == debian sid, so there are no diferences on that I didn't need an explanation of what equals what, I was correcting your generalized statement that apt-get worked on Linux. Consider RH derivatives, SUSE, et al --- yes, I know you can get apt to work on them, too, but that introduces complexity. The OP is using Debian, but not all users who check the archives for a solution, who may come across your message, will be using it. The correction was for that purpose. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
Am 25.01.2011 20:01, schrieb Daniel Brown: On Tue, Jan 25, 2011 at 13:54, Ronny Tiebel ronny.tie...@qumido.de wrote: ubuntu (10.10) == debian sid, so there are no diferences on that I didn't need an explanation of what equals what, I was correcting your generalized statement that apt-get worked on Linux. Consider RH derivatives, SUSE, et al --- yes, I know you can get apt to work on them, too, but that introduces complexity. The OP is using Debian, but not all users who check the archives for a solution, who may come across your message, will be using it. The correction was for that purpose. oh, ok, sorry for that. ive missunderstood your post. but he wrote that he's using debian sid so its a possible solution for him. never mind just wanted to help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On Tue, Jan 25, 2011 at 14:07, Ronny Tiebel ronny.tie...@qumido.de wrote: oh, ok, sorry for that. ive missunderstood your post. but he wrote that he's using debian sid so its a possible solution for him. never mind just wanted to help It is helpful, just correcting for the archives. Nothing against you at all, and no need to apologize. I think the solutions you guys have given the OP are just what he needs. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
Am 25.01.2011 20:09, schrieb Daniel Brown: On Tue, Jan 25, 2011 at 14:07, Ronny Tiebel ronny.tie...@qumido.de wrote: oh, ok, sorry for that. ive missunderstood your post. but he wrote that he's using debian sid so its a possible solution for him. never mind just wanted to help It is helpful, just correcting for the archives. Nothing against you at all, and no need to apologize. I think the solutions you guys have given the OP are just what he needs. Yes indeed, i didnt realized during writing that ive generalized that over all linux distributions. so youre right at that point. ;) Best Regards, Ronny -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
At 12:25 PM 1/25/2011, Nilesh Govindarajan wrote: On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanks. As far as I can tell, the PHP is installed directly on my computer. Now what? Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
On Tue, Jan 25, 2011 at 13:33, Ethan Rosenberg eth...@earthlink.net wrote: As far as I can tell, the PHP is installed directly on my computer. Now what? From the command line, type: which pear If it gives you a path, PEAR is installed, and you can use it as you desire. If it indicates that nothing was found, then you need to install it. PEAR is not part of the PHP packages provided by any OS vendors (or any package maintainers of which I'm aware). -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String Encodings - loose guidelines
Hello, I don't yet have a complete understanding of string encodings for the various environments they may need to pass through or be in. I have found bits and pieces within Larry's book, the online docs, and by googling... and my app seems to be working fine, but I don't yet feel confident on best practices. So, I thought I'd see if I could spark some feedback to the following: 1.) Saving strings to a database 2.) print/echo'ing string fields from a database. a. Allowing HTML? b. Not allowing HTML? 3.) print/echo'ing string fields into form textareas. 4.) Simply encoding strings to send over a GET request. 5.) Simply displaying strings from the $_REQUEST array. 6.) string encoding for redirects I understand that some of the above may depend on what database is being used. However, here is basically what I'm using successfully so far (disclaimer: obviously I am not sure of things here which is why I am asking the question ;-) ): 1.) $t_string = mysql_real_escape_string($f_varied_chars); //if using MySQL (optionally could use htmlspecialchars()?) to not allow html? 2.) print $db_string; a. Nothing different.. or perhaps htmlspecialchars_decode()? b. use htmlspecialchars upon saving to database, or using print htmlentities($db_string);?? 3.) textarea..?PHP print htmlspecialchars($db_string); ?/textarea? 4.) $t_string = urlencode($t_varied_chars); //(not sure if htmlentities would be needed in certain situations) a href=page.php?f_string=$t_stringx/a 5.) print urldecode($_GET['t_string']); //(not sure if html_entity_decode() would be needed in certain situations where you would want to display html?) 6.) ob_end_clean(); // destroy buffer $t_string = urlencode(text with varied chars); $t_url = page.php?f_string=$t_string; header (Location: $t_url); exit; TIA, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Encodings - loose guidelines
1.) Saving strings to a database One thing I always forget to remember is to send tge SET NAMES utf8 command to MySQL after making a connection. This will save you 1000 headaches if you're working with non-latin characters. I can't count the number of times I've thrown htmlentities, htmlspecialchars, utf8_encode/decode/, stripslashes, etc, etc around trying to figure out why those É's aren't being saved or read properly. I imagine this might fall into the category of best practice. Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Installing PEAR
At 01:44 PM 1/25/2011, Shawn McKenzie wrote: On 01/25/2011 11:25 AM, Nilesh Govindarajan wrote: On 01/25/2011 10:32 PM, Ethan Rosenberg wrote: Dear List -- How do install PEAR on Linux? I installed lynx and as root, I ran the command lynx -source http://pear.php.net/go-pear | php. It seemed to install, but the command pear did not work. From the root directory I ran the command find . -name pear. There was no file found. I also tried Pear, with the same results. Help and advice, please. Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] If you are using php from the repositories, there must be a pear package as well in the repos. Check for them. Yes, I'm on Ubuntu and just used 'apt-get install php-pear'. -- Thanks! -Shawn http://www.spidean.com -- Used apt-get install php-pear. It works!! Thanks to all. Ethan PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Formatting
Dear list - I have a program with the following statement: $out = system('ls -l', $retval); The output is a string. How do I format the output to be in the Linux format, that is in columns. I cannot think of a way to use explode to do it. Advice and comments, please. Thanks Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting
Ethan Rosenberg wrote: Dear list - I have a program with the following statement: $out = system('ls -l', $retval); The output is a string. How do I format the output to be in the Linux format, that is in columns. I cannot think of a way to use explode to do it. Advice and comments, please. Thanks Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] Something like?: print pre; $out = system('ls -l', $retval); print /pre; Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting
Hi You can try something like this: ?php ob_start(); system('ls', $retval); $raw = ob_get_contents(); ob_end_clean(); $arr = explode(chr(10),$raw); print_r($arr); it gives you a array back whit the lines 2011/1/26 Donovan Brooke li...@euca.us Ethan Rosenberg wrote: Dear list - I have a program with the following statement: $out = system('ls -l', $retval); The output is a string. How do I format the output to be in the Linux format, that is in columns. I cannot think of a way to use explode to do it. Advice and comments, please. Thanks Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] Something like?: print pre; $out = system('ls -l', $retval); print /pre; Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting
On 1/25/2011 9:05 PM, Ethan Rosenberg wrote: Dear list - I have a program with the following statement: $out = system('ls -l', $retval); The output is a string. How do I format the output to be in the Linux format, that is in columns. I cannot think of a way to use explode to do it. Advice and comments, please. Thanks Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] Well, depends, are you running this in a browser or at the console? If you are displaying this in a browser, you are probably seeing that browsers do not like \n (newlines) If in a browser, you could: 1) Wrap your output in a pre?php echo $out; ?/pre HTML tag 2) Use PHP's nl2br() to replace all newlines with br / tags 3) Use PHP's header() function to tell the browser to display the output as plaintext. i.e. header('Content-Type: text/plain'); [1,2] 1 - Google php header plain text 2 - http://www.php.net/manual/en/function.header.php#92620 If in cli... well, you wouldn't be having this problem... :) Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php