php-general Digest 19 Jun 2010 09:10:16 -0000 Issue 6806

Topics (messages 306246 through 306269):

Re: stripping first comma off and everything after
        306246 by: Robert Cummings
        306247 by: Adam
        306248 by: João Cândido de Souza Neto
        306249 by: Daniel P. Brown
        306263 by: shiplu
        306264 by: Robert Cummings
        306265 by: Troy Oltmanns
        306266 by: Robert Cummings
        306267 by: Adam Richardson
        306268 by: Adam Richardson
        306269 by: Ashley Sheridan

newbie sequel question: how do we search for multiple things on 1 field like:
        306250 by: Dave
        306252 by: Rick Dwyer
        306253 by: Daniel Brown
        306256 by: Dave
        306258 by: Daniel Brown

Replacing Registered Symbol
        306251 by: Rick Dwyer
        306254 by: Bob McConnell
        306255 by: Daniel Brown
        306257 by: Rick Dwyer
        306259 by: Daniel Brown
        306260 by: Rick Dwyer
        306261 by: Daniel P. Brown
        306262 by: Rick Dwyer

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Adam Williams wrote:
I'm querying data and have results such as a variable named $entries[$i]["dn"]:

CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx

Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.

I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything. Any ideas?

<?php

preg_replace( '#,.*$#', '', $entries[$i]['dn'] );

?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message --- I'm querying data and have results such as a variable named $entries[$i]["dn"]:

CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx

Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.

I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything. Any ideas?
--- End Message ---
--- Begin Message ---
Why not this?

$var = explode(",",$entries[$i]["dn"]);
$var = $var[0];

"Adam Williams" <[email protected]> escreveu na mensagem 
news:[email protected]...
> I'm querying data and have results such as a variable named 
> $entries[$i]["dn"]:
>
> CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx
>
> Basically I need to strip off the first command everything after, so that 
> I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.
>
> I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything. 
> Any ideas?
> 



--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 15:56, Adam Williams
<[email protected]> wrote:
> I'm querying data and have results such as a variable named
> $entries[$i]["dn"]:
>
> CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx
>
> Basically I need to strip off the first command everything after, so that I
> just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.
>
> I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything.
>  Any ideas?

    Check out substr() with strpos().

<?php
$s = 
'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx';

if (substr($s,0,strpos($s,',')) ==
'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92') {
        echo "Good.".PHP_EOL;
} else {
        echo "Bad.".PHP_EOL;
}
?>

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

--- End Message ---
--- Begin Message ---
I'll use,

list($data) = explode(",",$entries[$i]["dn"]);


Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

--- End Message ---
--- Begin Message ---
shiplu wrote:
I'll use,

list($data) = explode(",",$entries[$i]["dn"]);


It's probably the least efficient method.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
http://php.net/manual/en/function.split.php

I haven't tested for efficiency but splitting it will be great for assigning
it easily into an array.

On Fri, Jun 18, 2010 at 7:42 PM, Robert Cummings <[email protected]>wrote:

> shiplu wrote:
>
>> I'll use,
>>
>> list($data) = explode(",",$entries[$i]["dn"]);
>>
>>
> It's probably the least efficient method.
>
>
> Cheers,
> Rob.
> --
> E-Mail Disclaimer: Information contained in this message and any
> attached documents is considered confidential and legally protected.
> This message is intended solely for the addressee(s). Disclosure,
> copying, and distribution are prohibited unless authorized.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Troy Oltmanns wrote:
http://php.net/manual/en/function.split.php

I haven't tested for efficiency but splitting it will be great for assigning
it easily into an array.

Explode does the same thing without the overhead of a regular expression engine.

But the OP didn't want the rest :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 3:56 PM, Adam Williams
<[email protected]>wrote:

> I'm querying data and have results such as a variable named
> $entries[$i]["dn"]:
>
> CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx
>
>
> Basically I need to strip off the first command everything after, so that I
> just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.
>
> I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything.
>  Any ideas?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Adam (how could I not offer feedback to one with such a distinguished first
name),

rtrim() removes the characters contained in the second argument, it doesn't
split a string using them.

I would probably use strstr() if I didn't need the other sections, or, if I
needed the other sections for later, I'd use explode:

$your_string =
'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx,';

echo strstr($haystack = $your_string, $needle = ',', $before_needle = true);

if ($sections = explode($delimiter = ',', $string = $your_string)) echo
current($sections);

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Sat, Jun 19, 2010 at 3:08 AM, Adam Richardson <[email protected]>wrote:

> On Fri, Jun 18, 2010 at 3:56 PM, Adam Williams <
> [email protected]> wrote:
>
>> I'm querying data and have results such as a variable named
>> $entries[$i]["dn"]:
>>
>> CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx
>>
>>
>> Basically I need to strip off the first command everything after, so that
>> I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.
>>
>> I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do anything.
>>  Any ideas?
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> Adam (how could I not offer feedback to one with such a distinguished first
> name),
>
> rtrim() removes the characters contained in the second argument, it doesn't
> split a string using them.
>
> I would probably use strstr() if I didn't need the other sections, or, if I
> needed the other sections for later, I'd use explode:
>
> $your_string =
> 'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx,';
>
> echo strstr($haystack = $your_string, $needle = ',', $before_needle =
> true);
>
> if ($sections = explode($delimiter = ',', $string = $your_string)) echo
> current($sections);
>
> Adam
>
> --
> Nephtali:  PHP web framework that functions beautifully
> http://nephtaliproject.com
>

Whoops!

I realized in the explode example I had omitted the call to count (idea
being if you didn't find any comma's, maybe you need to handle those
situations differently):

if (count($sections = explode($delimiter = ',', $string = $your_string)) >
1) echo $sections[0];

Although, if it doesn't matter, you could just do:

echo current(explode(',', $your_string));

And, as mentioned above, strstr() is one simple call if you won't need the
other sections:

echo strstr($your_string, ',' true);

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Fri, 2010-06-18 at 15:03 -0500, Adam wrote:

> I'm querying data and have results such as a variable named 
> $entries[$i]["dn"]:
> 
> CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXXXXXXXXXf,OU=XXXXXXXXXX,OU=XXXXXXXXXXXXX,DC=xxxxxxxx,DC=xxxxxxxxxx,DC=xxx
>  
> 
> 
> Basically I need to strip off the first command everything after, so 
> that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92.
> 
> I tried echo rtrim($entries[$i]["dn"],","); but that doesn't do 
> anything.  Any ideas?
> 


A substring() a strpos() should do the trick:

substring($entries[$i]['dn'], 0, strpos($entries[$i]['dn']-1))

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



--- End Message ---
--- Begin Message ---
SELECT * FROM contacts WHERE state = 'CA' and  ???? name = 'bob' or
name = 'sam' or name = 'sara' ????

-- 
Thanks - Dave

--- End Message ---
--- Begin Message --- SELECT * FROM contacts WHERE state = 'CA' and (name = 'bob' or name = 'sam' or name = 'sara')

 --Rick


On Jun 18, 2010, at 4:30 PM, Dave wrote:

SELECT * FROM contacts WHERE state = 'CA' and  ???? name = 'bob' or
name = 'sam' or name = 'sara' ????

--
Thanks - Dave

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



--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 16:30, Dave <[email protected]> wrote:
> SELECT * FROM contacts WHERE state = 'CA' and  ???? name = 'bob' or
> name = 'sam' or name = 'sara' ????

    We begin by asking on the right list ([email protected], CC'd
by courtesy).

    You're on the right track though.  Try a WHERE...IN statement:

    SELECT * FROM contacts WHERE state='CA' AND name IN ('bob','sam','sara');

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

--- End Message ---
--- Begin Message ---
Thanks Daniel and Rick!


I will start using this...

   We begin by asking on the right list ([email protected], CC'd
by courtesy).

Thanks,
Dave
[email protected]
[db-10]


--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 17:06, [email protected] <[email protected]> wrote:
>
> I will start using this...
>
>   We begin by asking on the right list ([email protected], CC'd
> by courtesy).

    It was just an end-of-the-week jab, Dave.  I mean, that's the
correct list to use, but the response should've had a tongue-out
smiley or some kind of drunk purple unicorn dancing to MC Hammer or
something to show that it wasn't meant as harsh as it may have
sounded.

-- 
</Daniel P. Brown>
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

--- End Message ---
--- Begin Message ---
Hello List.

I'm trying to replace the registered (®) symbol from a variable via PHP.

The variable $mystring is set to a MySQL field that contains the value "This Is The Registered Symbol ®".

Using the following, I try to replace the symbol, but it persists:

$moditem = str_replace("®","","$mystring");

I tried replacing the symbol in the above syntax with the HTML equivalent but no luck.

Any help is appreciated.

Thanks,

 --Rick



--- End Message ---
--- Begin Message ---
From: Rick Dwyer

> I'm trying to replace the registered ((r)) symbol from a variable via
PHP.
> 
> The variable $mystring is set to a MySQL field that contains the value

> "This Is The Registered Symbol (r)".
> 
> Using the following, I try to replace the symbol, but it persists:
> 
> $moditem = str_replace("(r)","","$mystring");
> 
> I tried replacing the symbol in the above syntax with the HTML  
> equivalent but no luck.

It depends on what you want it for. For a URL, the HTML encoding is
'&reg;' '&#174;' or '%AE'.

Bob McConnell

--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 16:32, Rick Dwyer <[email protected]> wrote:
> Hello List.
>
> I'm trying to replace the registered (®) symbol from a variable via PHP.
>
> The variable $mystring is set to a MySQL field that contains the value "This
> Is The Registered Symbol ®".
>
> Using the following, I try to replace the symbol, but it persists:
>
> $moditem = str_replace("®","","$mystring");
>
> I tried replacing the symbol in the above syntax with the HTML equivalent
> but no luck.

    Check your database's character encoding.  My check:

<?php
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM `example`"));

$mystring = $row['testfield'];

$moditem = str_replace("®","",$mystring);

echo $moditem.PHP_EOL;
?>

    .... worked as expected.  Note that, while it won't make a
difference in your result here, you don't need to use quotes around
your variable in the str_replace() call you showed.  In fact, not only
would it slow down the processes on more-involved or more-popular
sites, but it'll have a larger impact, as you're using double quotes,
which are first evaluated, then passed.  Single quotes would, of
course, literally echo $mystring in your case, but you get the point.
Just a quick tip.

-- 
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/

--- End Message ---
--- Begin Message ---

On Jun 18, 2010, at 4:52 PM, Daniel Brown wrote:


   Check your database's character encoding.  My check:


Navicat shows it as Latin1. I believe UTF-8 is what it should be, but I don't want to change it without understanding what impact it will have.

 Note that, while it won't make a
difference in your result here, you don't need to use quotes around
your variable in the str_replace() call you showed.  In fact, not only
would it slow down the processes on more-involved or more-popular
sites, but it'll have a larger impact, as you're using double quotes,
which are first evaluated, then passed.  Single quotes would, of
course, literally echo $mystring in your case, but you get the point.
Just a quick tip.

Did not know, thanks.

--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 17:07, Rick Dwyer <[email protected]> wrote:
>
> Navicat shows it as Latin1.  I believe UTF-8 is what it should be, but I
> don't want to change it without understanding what impact it will have.

    Depending on your content, it could be an issue, but probably not.
 A good way to check would be to copy the table, convert the encoding,
and test it.  However, my example database with LATIN1 collation still
worked as expected here.  So that may not be the issue for you after
all.

    Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?

-- 
</Daniel P. Brown>
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

--- End Message ---
--- Begin Message ---

On Jun 18, 2010, at 5:13 PM, Daniel Brown wrote:


   Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?


No, I'm on Mac OS 10.5 and apparently I don't have a MySQL client installed in terminal. I've always used Navicat and never had a need for the terminal.... until now.
--- End Message ---
--- Begin Message ---
On Fri, Jun 18, 2010 at 17:37, Rick Dwyer <[email protected]> wrote:
>
> No, I'm on Mac OS 10.5 and apparently I don't have a MySQL client installed
> in terminal.  I've always used Navicat and never had a need for the
> terminal.... until now.

    Should be able to install mysql-client from ports.  Not positive
on the name since it's been a while since I've played with a web Mac
personally.  I can ask someone here if you can't figure it out.

-- 
</Daniel P. Brown>
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

--- End Message ---
--- Begin Message --- OK, it's definitely an encoding issue... when I change the encoding of my PHP page in BBedit to Western ISO Latin 1, it replaces successfully.



 --Rick


On Jun 18, 2010, at 5:13 PM, Daniel Brown wrote:

On Fri, Jun 18, 2010 at 17:07, Rick Dwyer <[email protected]> wrote:

Navicat shows it as Latin1. I believe UTF-8 is what it should be, but I don't want to change it without understanding what impact it will have.

   Depending on your content, it could be an issue, but probably not.
A good way to check would be to copy the table, convert the encoding,
and test it.  However, my example database with LATIN1 collation still
worked as expected here.  So that may not be the issue for you after
all.

   Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?

--
</Daniel P. Brown>
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

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



--- End Message ---

Reply via email to