php-general Digest 2 Apr 2010 23:05:23 -0000 Issue 6672

2010-04-02 Thread php-general-digest-help

php-general Digest 2 Apr 2010 23:05:23 - Issue 6672

Topics (messages 303749 through 303755):

str_replace help
303749 by: David Stoltz
303750 by: Ashley Sheridan
303751 by: Midhun Girish
303752 by: Nilesh Govindarajan

SimpleXMLElement and gb2312 or big5
303753 by: Peter Pei

SimpleXMLElement occasionally fails to parse gb2312 or big5 feeds
303754 by: Peter Pei

convert a string into an array
303755 by: Andre Polykanine

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Hi folks,
 
In ASP, I would commonly replace string line feeds for HTML output like
this:
 
Var = replace(value,vbcrlf,br)
 
In PHP, the following doesn't seem to work:
$var = str_replace(chr(13),\n,$value)
 
Neither does:
$var = str_replace(chr(10),\n,$value)
 
What am I doing wrong?
 
Thanks!
---End Message---
---BeginMessage---
On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

 Hi folks,
  
 In ASP, I would commonly replace string line feeds for HTML output like
 this:
  
 Var = replace(value,vbcrlf,br)
  
 In PHP, the following doesn't seem to work:
 $var = str_replace(chr(13),\n,$value)
  
 Neither does:
 $var = str_replace(chr(10),\n,$value)
  
 What am I doing wrong?
  
 Thanks!


I see no reason why it shouldn't work other than maybe the string
doesn't contain what you think it does.

Thanks,
Ash
http://www.ashleysheridan.co.uk


---End Message---
---BeginMessage---
well david actually $var = str_replace(chr(13),\n,$value) will replace
char(13) with \n... but \n wont come up in html unless u give a pre tag..
u need to put

$var = str_replace(chr(13),br/,$value) in order to got the required
output


Midhun Girish


On Fri, Apr 2, 2010 at 7:03 PM, Ashley Sheridan 
a...@ashleysheridan.co.ukwrote:

 On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

  Hi folks,
 
  In ASP, I would commonly replace string line feeds for HTML output like
  this:
 
  Var = replace(value,vbcrlf,br)
 
  In PHP, the following doesn't seem to work:
  $var = str_replace(chr(13),\n,$value)
 
  Neither does:
  $var = str_replace(chr(10),\n,$value)
 
  What am I doing wrong?
 
  Thanks!


 I see no reason why it shouldn't work other than maybe the string
 doesn't contain what you think it does.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



---End Message---
---BeginMessage---

On 04/02/10 18:58, David Stoltz wrote:

Hi folks,

In ASP, I would commonly replace string line feeds for HTML output like
this:

Var = replace(value,vbcrlf,br)

In PHP, the following doesn't seem to work:
$var = str_replace(chr(13),\n,$value)

Neither does:
$var = str_replace(chr(10),\n,$value)

What am I doing wrong?

Thanks!



Use nl2br.

--
Nilesh Govindarajan
Site  Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !
---End Message---
---BeginMessage---
I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);
---End Message---
---BeginMessage---


I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
---End Message---
---BeginMessage---
Hello everyone,

It's quite simple but I'm still stuck.
What I need is the following: I have an array as a parameter of my
custom function. However, I'd like to allow users to enter a string
instead of an array. In this case (if the parameter is a string), it
must be replaced with an array containing only one item - actually,
that string.
What I'm doing gives me (presumably) errors;
function Send ($tonames, $toemails, $subject, $message) {
...
if ((!is_array($tonames)) || (!is_array($toemails))) {
$tonames[]=$tonames;
$toemails[]=$toemails;
}

I can't give the new array a new name since I address it further in a
loop as my function's parameter... hope you understand what I'm
saying)
Thanks!

-- 
With best regards from Ukraine,
Andre
Http://oire.org/ - The Fantasy blogs of Oire
Skype: Francophile; WlmMSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
jabber.org

Re: [PHP] How to know which PHP is used by Apache

2010-04-02 Thread Devendra Jadhav
On Thu, Apr 1, 2010 at 11:30 PM, Nilesh Govindarajan li...@itech7.comwrote:

 On 04/01/10 23:03, Kevin Kinsey wrote:

 Nilesh Govindarajan wrote:

 libphp5.so doesn't need the php binary.


 You're right, and of course not. libphp5.so
 *is* a PHP binary :-)

  I've confirmed this using a test.

 My local apache is configured to use libphp5.so

 I moved /usr/bin/php to /root, then started apache and ran drupal. It
 worked.

 This confirms that libphp5.so is independent of the php binary in
 /usr/bin as I suggested earlier.


 No one was questioning that .. or at least, I wasn't.
 One is an executable binary file ... a program.

 The other is also a binary file, but it's a _library_.

 What I said was you need one or the other. A binary
 file, either the Apache SO or the binary interpreter...

 It's possible to configure Apache to use a PHP executable
 (CGI), and the CGI and CLI executables are similar, if
 not identical.

 I dunno if anyone actually does that anymore, though. :-)

 Ashley said The libphp5.so is the Apache module that
 links PHP into Apache. You need this and PHP installed
 if you want to use PHP in Apache. Devendra apparently
 misinterpreted this to mean that you need both the SO and
 the binary interpreter, but you don't. You DO need the
 rest of the PHP extensions, libraries, config files, etc.
 ... a PHP installation, whether or not your have the
 CLI binary is not that important, although I always do
 since I like to run system scripts in PHP via cron, etc.

 Kevin Kinsey


 LOL. Super misunderstanding. Anyway, I did that test to help Devendra.


 --
 Nilesh Govindarajan
 Site  Server Administrator
 www.itech7.com
 मेरा भारत महान !
 मम भारत: महत्तम भवतु !

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


I think I am clear with everything now.. Good.. Thank you very much Nilesh,
kevin, Ashley  all.


-- 
Devendra Jadhav
देवेंद्र जाधव


[PHP] str_replace help

2010-04-02 Thread David Stoltz
Hi folks,
 
In ASP, I would commonly replace string line feeds for HTML output like
this:
 
Var = replace(value,vbcrlf,br)
 
In PHP, the following doesn't seem to work:
$var = str_replace(chr(13),\n,$value)
 
Neither does:
$var = str_replace(chr(10),\n,$value)
 
What am I doing wrong?
 
Thanks!


Re: [PHP] str_replace help

2010-04-02 Thread Ashley Sheridan
On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

 Hi folks,
  
 In ASP, I would commonly replace string line feeds for HTML output like
 this:
  
 Var = replace(value,vbcrlf,br)
  
 In PHP, the following doesn't seem to work:
 $var = str_replace(chr(13),\n,$value)
  
 Neither does:
 $var = str_replace(chr(10),\n,$value)
  
 What am I doing wrong?
  
 Thanks!


I see no reason why it shouldn't work other than maybe the string
doesn't contain what you think it does.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] str_replace help

2010-04-02 Thread Midhun Girish
well david actually $var = str_replace(chr(13),\n,$value) will replace
char(13) with \n... but \n wont come up in html unless u give a pre tag..
u need to put

$var = str_replace(chr(13),br/,$value) in order to got the required
output


Midhun Girish


On Fri, Apr 2, 2010 at 7:03 PM, Ashley Sheridan 
a...@ashleysheridan.co.ukwrote:

 On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

  Hi folks,
 
  In ASP, I would commonly replace string line feeds for HTML output like
  this:
 
  Var = replace(value,vbcrlf,br)
 
  In PHP, the following doesn't seem to work:
  $var = str_replace(chr(13),\n,$value)
 
  Neither does:
  $var = str_replace(chr(10),\n,$value)
 
  What am I doing wrong?
 
  Thanks!


 I see no reason why it shouldn't work other than maybe the string
 doesn't contain what you think it does.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] str_replace help

2010-04-02 Thread Nilesh Govindarajan

On 04/02/10 18:58, David Stoltz wrote:

Hi folks,

In ASP, I would commonly replace string line feeds for HTML output like
this:

Var = replace(value,vbcrlf,br)

In PHP, the following doesn't seem to work:
$var = str_replace(chr(13),\n,$value)

Neither does:
$var = str_replace(chr(10),\n,$value)

What am I doing wrong?

Thanks!



Use nl2br.

--
Nilesh Govindarajan
Site  Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXMLElement and gb2312 or big5

2010-04-02 Thread Peter Pei
I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXMLElement occasionally fails to parse gb2312 or big5 feeds

2010-04-02 Thread Peter Pei


I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] convert a string into an array

2010-04-02 Thread Andre Polykanine
Hello everyone,

It's quite simple but I'm still stuck.
What I need is the following: I have an array as a parameter of my
custom function. However, I'd like to allow users to enter a string
instead of an array. In this case (if the parameter is a string), it
must be replaced with an array containing only one item - actually,
that string.
What I'm doing gives me (presumably) errors;
function Send ($tonames, $toemails, $subject, $message) {
...
if ((!is_array($tonames)) || (!is_array($toemails))) {
$tonames[]=$tonames;
$toemails[]=$toemails;
}

I can't give the new array a new name since I address it further in a
loop as my function's parameter... hope you understand what I'm
saying)
Thanks!

-- 
With best regards from Ukraine,
Andre
Http://oire.org/ - The Fantasy blogs of Oire
Skype: Francophile; WlmMSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: http://twitter.com/m_elensule


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match? Or something else?

2010-04-02 Thread Ashley M. Kirchner
I have an array that's created as follows:

 

$string = 73G146C   311- 309.1C;

$arr = preg_split(/[\s]+/, $string);

 

Now I need to take each element in that array, and break them up even
further so that I get:

 

73G= 73 and G

146C   = 146 and C

311-   = 311 and -

309.1C = 309, 1, and C  (notice 3 elements here)

 

I'm having a hard time trying to figure out what the proper regex would be
for this, or whether that's the right thing to do.  So far I've gotten this:

 

  preg_match(/^(?Plocation\d+)(?Pletter[A-Z-])/, $item, $matches);

  print_r($matches);

 

Which gives me:

 

Array

(

[0] = 73G

[location] = 73

[1] = 73

[letter] = G

[2] = G

)

Array

(

[0] = 146C

[location] = 146

[1] = 146

[letter] = C

[2] = C

)

Array

(

[0] = 311-

[location] = 311

[1] = 311

[letter] = -

[2] = -

)

Array

(

)

 

 

However that's as far as it goes.  For the other number it returns an empty
array and I know why, the decimal point.   Now I can evaluate each $item
every time, see if they contain a decimal point, and pass it to a different
regex string, but that seems rather inefficient to me.  So how can I do this
all in one fell swoop?

 

Anyone want to take a stab at it?



Re: [PHP] convert a string into an array

2010-04-02 Thread Jim Lucas
Andre Polykanine wrote:
 Hello everyone,
 
 It's quite simple but I'm still stuck.
 What I need is the following: I have an array as a parameter of my
 custom function. However, I'd like to allow users to enter a string
 instead of an array. In this case (if the parameter is a string), it
 must be replaced with an array containing only one item - actually,
 that string.
 What I'm doing gives me (presumably) errors;
 function Send ($tonames, $toemails, $subject, $message) {
 ...
 if ((!is_array($tonames)) || (!is_array($toemails))) {
 $tonames[]=$tonames;
 $toemails[]=$toemails;
 }
 
 I can't give the new array a new name since I address it further in a
 loop as my function's parameter... hope you understand what I'm
 saying)
 Thanks!
 

Do something like this:

$tonames  = (is_array($tonames)  ? $tonames  : array($tonames) );
$toemails = (is_array($toemails) ? $toemails : array($toemails));

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: convert a string into an array

2010-04-02 Thread Nathan Rixham
Andre Polykanine wrote:
 Hello everyone,
 
 It's quite simple but I'm still stuck.
 What I need is the following: I have an array as a parameter of my
 custom function. However, I'd like to allow users to enter a string
 instead of an array. In this case (if the parameter is a string), it
 must be replaced with an array containing only one item - actually,
 that string.
 What I'm doing gives me (presumably) errors;
 function Send ($tonames, $toemails, $subject, $message) {
 ...
 if ((!is_array($tonames)) || (!is_array($toemails))) {
 $tonames[]=$tonames;
 $toemails[]=$toemails;
 }
 
 I can't give the new array a new name since I address it further in a
 loop as my function's parameter... hope you understand what I'm
 saying)
 Thanks!
 

function send( $tonames , $toemails , $subject , $message )
{
  $tonames = (array)$tonames;
  $toemails = (array)$toemails;
}

type juggling is a wonderful thing ;)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match? Or something else?

2010-04-02 Thread Jim Lucas
Ashley M. Kirchner wrote:
 I have an array that's created as follows:
 
  
 
 $string = 73G146C   311- 309.1C;
 
 $arr = preg_split(/[\s]+/, $string);
 
  
 
 Now I need to take each element in that array, and break them up even
 further so that I get:
 
  
 
 73G= 73 and G
 
 146C   = 146 and C
 
 311-   = 311 and -
 
 309.1C = 309, 1, and C  (notice 3 elements here)
 
  
 
 I'm having a hard time trying to figure out what the proper regex would be
 for this, or whether that's the right thing to do.  So far I've gotten this:
 
  
 
   preg_match(/^(?Plocation\d+)(?Pletter[A-Z-])/, $item, $matches);
 
   print_r($matches);
 
  
 
 Which gives me:
 
  
 
 Array
 
 (
 
 [0] = 73G
 
 [location] = 73
 
 [1] = 73
 
 [letter] = G
 
 [2] = G
 
 )
 
 Array
 
 (
 
 [0] = 146C
 
 [location] = 146
 
 [1] = 146
 
 [letter] = C
 
 [2] = C
 
 )
 
 Array
 
 (
 
 [0] = 311-
 
 [location] = 311
 
 [1] = 311
 
 [letter] = -
 
 [2] = -
 
 )
 
 Array
 
 (
 
 )
 
 However that's as far as it goes.  For the other number it returns an empty
 array and I know why, the decimal point.   Now I can evaluate each $item
 every time, see if they contain a decimal point, and pass it to a different
 regex string, but that seems rather inefficient to me.  So how can I do this
 all in one fell swoop?
 
 Anyone want to take a stab at it?
 
 

Conditionals are your friend!

plaintext?php

$string = 73G146C   311- 309.1C;

$arr = preg_split(/[\s]+/, $string);

print_r($arr);

foreach ( $arr AS $item ) {
preg_match('|^(?Plocation\d+)\.?(?Pdecimal\d*)(?Pletter[A-Z-])|',
   $item,
   $matches);

print_r($matches);
}

?

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match? Or something else?

2010-04-02 Thread Nathan Rixham
Jim Lucas wrote:
 Ashley M. Kirchner wrote:
 I have an array that's created as follows:

  

 $string = 73G146C   311- 309.1C;


 Anyone want to take a stab at it?


 
 Conditionals are your friend!
 
 plaintext?php
 
 $string = 73G146C   311- 309.1C;
 
 $arr = preg_split(/[\s]+/, $string);
 
 print_r($arr);
 
 foreach ( $arr AS $item ) {
   preg_match('|^(?Plocation\d+)\.?(?Pdecimal\d*)(?Pletter[A-Z-])|',
$item,
$matches);
 
   print_r($matches);
 }
 
 ?
 

or w/ preg_match_all:

?php
$regex = '/(([0-9]+)([^0-9])((?:[0-9]|\s+)))/';
$string = 73G146C   311- 309.1C;
preg_match_all( $regex , $string , $matches );
print_r( $matches )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] array or list of objects of different types

2010-04-02 Thread Php Developer
Hi all,

I want to be able to have an array of elements of different types. As an 
example: the first element is a boolean, the second is an integer, and the 
thirs is a string.

In php there is no typing, i'm just wondering if there is a way to have that, 
it would be a lot better than having an array of strings and have to convert 
each element.

Thank you



  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

[PHP] Re: array or list of objects of different types

2010-04-02 Thread Nathan Rixham
Php Developer wrote:
 Hi all,
 
 I want to be able to have an array of elements of different types. As an 
 example: the first element is a boolean, the second is an integer, and the 
 thirs is a string.
 
 In php there is no typing, i'm just wondering if there is a way to have that, 
 it would be a lot better than having an array of strings and have to convert 
 each element.
 

var_dump( array( true , 12 , php already does this ) );

array(3) {
  [0]= bool(true)
  [1]= int(12)
  [2]= string(21) php already does this
}

:)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: convert a string into an array

2010-04-02 Thread Nilesh Govindarajan

On 04/03/10 04:56, Nathan Rixham wrote:

Andre Polykanine wrote:

Hello everyone,

It's quite simple but I'm still stuck.
What I need is the following: I have an array as a parameter of my
custom function. However, I'd like to allow users to enter a string
instead of an array. In this case (if the parameter is a string), it
must be replaced with an array containing only one item - actually,
that string.
What I'm doing gives me (presumably) errors;
function Send ($tonames, $toemails, $subject, $message) {
...
if ((!is_array($tonames)) || (!is_array($toemails))) {
$tonames[]=$tonames;
$toemails[]=$toemails;
}

I can't give the new array a new name since I address it further in a
loop as my function's parameter... hope you understand what I'm
saying)
Thanks!



function send( $tonames , $toemails , $subject , $message )
{
   $tonames = (array)$tonames;
   $toemails = (array)$toemails;
}

type juggling is a wonderful thing ;)



Yeah this i the best. It will allow the users to enter a string or an 
array without affecting processing of your function.


--
Nilesh Govindarajan
Site  Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: array or list of objects of different types

2010-04-02 Thread Nilesh Govindarajan

On 04/03/10 05:42, Nathan Rixham wrote:

Php Developer wrote:

Hi all,

I want to be able to have an array of elements of different types. As an 
example: the first element is a boolean, the second is an integer, and the 
thirs is a string.

In php there is no typing, i'm just wondering if there is a way to have that, 
it would be a lot better than having an array of strings and have to convert 
each element.



var_dump( array( true , 12 , php already does this ) );

array(3) {
   [0]=  bool(true)
   [1]=  int(12)
   [2]=  string(21) php already does this
}

:)



Yeah. But this feature of PHP is a boon if used carefully and a curse if 
careless. You can get AMAZING results if you're not careful to check the 
data types ;)


--
Nilesh Govindarajan
Site  Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php