php-general Digest 31 Jul 2009 09:31:41 -0000 Issue 6259
Topics (messages 296076 through 296096):
Re: regex - filtering out chinese utf8 characters
296076 by: Jim Lucas
Re: Asterisk anyone?
296077 by: Skip Evans
296085 by: Nathan Nobbe
296093 by: Per Jessen
Formatting plain text file
296078 by: Skip Evans
296079 by: Jim Lucas
296080 by: Skip Evans
296081 by: Robert Cummings
296088 by: b
296089 by: kranthi
This isn't infinitely recursive is it?
296082 by: Matt Neimeyer
296083 by: Jonathan Tapicer
296084 by: Ben Dunlap
296086 by: Ben Dunlap
Better Formatting Options?
296087 by: sono-io.fannullone.us
296096 by: Richard Heyes
Re: fileinfo returning wrong mime type for Excel files
296090 by: b
PHP 5.2.9 + NCurses
296091 by: Martin Scotta
Extract an element from XML
296092 by: Angelo Zanetti
Re: Ridiculous ..won't print or echo ...(RESOLVED)
296094 by: Ondr(ej S(ibr(ina
296095 by: Ondr(ej S(ibr(ina
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
----------------------------------------------------------------------
--- Begin Message ---
Merlin Morgenstern wrote:
> Hi there,
>
> I am trying to filter out content that is not ascii. Can I do this with
> regex? For example:
>
> $regex = '[AZ][09]';
> if (preg_match($regex, $text)) {
> return TRUE;
> }
> else {
> return FALSE;
> }
>
> The reason I need to do this is that I am doing a mysql query with the
> text and I need to make sure it is not UTF8. Otherwise I do get
> following error:
>
> Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT)
> and (utf8_general_ci,COERCIBLE) for operation '='
>
> I am new to regex and would be happy for a jump start to get this fixed.
>
> Best regards, Merlin
>
You might want to read up on iconv. I think it will do what you are
wanting to do.
http://us2.php.net/manual/en/book.iconv.php
specifically...
http://us2.php.net/manual/en/function.iconv.php
--- End Message ---
--- Begin Message ---
I'm looking at this page now that shows working with the
database through socket type stuff, but now the ball is in the
client's court what they want to do. Not sure, so I'm just
reading up.
http://www.voip-info.org/tiki-index.php?page=Web+based+Asterisk+Database+maintenance
But thanks all for the pointers. It has been helpful. I've
looked up Trixbox, thanks.
Skip
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--- End Message ---
--- Begin Message ---
On Wed, Jul 29, 2009 at 1:18 PM, Skip Evans <s...@bigskypenguin.com> wrote:
> Hey,
>
> I've been asked to write a simple couple of public pages that would let an
> Asterisk customer modify their account configuration, but the client has no
> idea how Asterisk stores its data, apparently not in MySQL.
>
> Anyone know of any resources for accessing Asterisk from PHP?
>
> If anyone has done this can you tell me if I'm on the right track here?
>
> http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples
this should get you off to a good start,
http://www.voip-info.org/wiki/view/Asterisk+CDR+csv+mysql+import
-nathan
--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
> On Wed, Jul 29, 2009 at 1:18 PM, Skip Evans <s...@bigskypenguin.com>
> wrote:
>
>> Hey,
>>
>> I've been asked to write a simple couple of public pages that would
>> let an Asterisk customer modify their account configuration, but the
>> client has no idea how Asterisk stores its data, apparently not in
>> MySQL.
>>
>> Anyone know of any resources for accessing Asterisk from PHP?
>>
>> If anyone has done this can you tell me if I'm on the right track
>> here?
>>
>>
http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples
>
>
> this should get you off to a good start,
>
> http://www.voip-info.org/wiki/view/Asterisk+CDR+csv+mysql+import
Yes, the CDR is often recorded in a database, but it's write-only as far
as Asterisk is concerned. It can be used for billing and such
afterwards, but then we're no longer in Asterisk territory.
/Per
--
Per Jessen, Zürich (17.8°C)
--- End Message ---
--- Begin Message ---
Hey all,
Am I brain fading or what? I'm so used to formatting text in
tables for HTML display I can't think of how to do it for a
plain text file.
I just need to create a columned table of names and addresses
type stuff... sprintf?
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--- End Message ---
--- Begin Message ---
Skip Evans wrote:
> Hey all,
>
> Am I brain fading or what? I'm so used to formatting text in tables for
> HTML display I can't think of how to do it for a plain text file.
>
> I just need to create a columned table of names and addresses type
> stuff... sprintf?
or a little str_pad on each variable...
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Skip Evans wrote:
Hey all,
Am I brain fading or what? I'm so used to formatting text in tables for
HTML display I can't think of how to do it for a plain text file.
I just need to create a columned table of names and addresses type
stuff... sprintf?
or a little str_pad on each variable...
Sure, that will do it. But isn't there some way to construct
formatted tables similar to HTML?
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--- End Message ---
--- Begin Message ---
Skip Evans wrote:
Jim Lucas wrote:
Skip Evans wrote:
Hey all,
Am I brain fading or what? I'm so used to formatting text in tables for
HTML display I can't think of how to do it for a plain text file.
I just need to create a columned table of names and addresses type
stuff... sprintf?
or a little str_pad on each variable...
Sure, that will do it. But isn't there some way to construct
formatted tables similar to HTML?
You can use a combination of wordwrap(), str_pad(), and swathe of
judicious (but simplistic) math :)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On 07/30/2009 06:29 PM, Skip Evans wrote:
Jim Lucas wrote:
Skip Evans wrote:
Hey all,
Am I brain fading or what? I'm so used to formatting text in tables for
HTML display I can't think of how to do it for a plain text file.
I just need to create a columned table of names and addresses type
stuff... sprintf?
or a little str_pad on each variable...
Sure, that will do it. But isn't there some way to construct formatted
tables similar to HTML?
Are you thinking of a CSV file that you can open in a spreadsheet prog?
Or, do you literally mean a plaintext file with columns? For the latter,
you'd need to measure the max char length of each "column" for every
line in the file, then go back and print each line using str_pad().
--- End Message ---
--- Begin Message ---
<?php
//assuming you have a 2d matrix $table
$table = array(
array("c11", "c12", "c13"),
array("c21", "c22", "c23")
);
foreach($table as $rows) {
$row = vsprintf(str_repeat("%-10s", count($rows)), $rows);
echo "{$row}<br />\n";
}
wont this do ?
--- End Message ---
--- Begin Message ---
I'm cleaning up some inherited code in our data import module. For a
variety of reasons we have to support old standards of the import
format. Since some of those old versions were created we have since
renamed some fields in our data structure. So right now I've a hard
map for some field names...
function GetMappedField($Field)
{
$FieldMap["A"] = "B";
$FieldMap["C"] = "D";
return isset($FieldMap[$Field])?$FieldMap[$Field]:$Field);
}
But I've just spent a while tracking down a bug where someone mapped A
to B and then someone else mapped B to C.
I'm thinking of changing the return to...
return isset($FieldMap[$Field])?GetMappedField($FieldMap[$Field]):$Field);
...but I'm worried about the recursion. (Which isn't a strength of mine)
I don't THINK I need to worry about circular mappings... but I'm not
sure how to check for it if I did...
Any suggestions? Thanks!
Matt
--- End Message ---
--- Begin Message ---
Hi,
Well, you will have an infinite recursion there if the mapping has
cycles, something like A->B, B->C, C->A would generate an invite
recursion.
Checking if the mapping has cycles is pretty simple: you have to
create a directed graph and then go through the graph in DFS marking
each visited node, if you have to mark a node already marked then you
have a cycle. Tarjan's algorithm does that and a little more, see
here:
http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
Hope that helps.
Jonathan
On Thu, Jul 30, 2009 at 8:38 PM, Matt Neimeyer<m...@neimeyer.org> wrote:
> I'm cleaning up some inherited code in our data import module. For a
> variety of reasons we have to support old standards of the import
> format. Since some of those old versions were created we have since
> renamed some fields in our data structure. So right now I've a hard
> map for some field names...
>
> function GetMappedField($Field)
> {
> $FieldMap["A"] = "B";
> $FieldMap["C"] = "D";
>
> return isset($FieldMap[$Field])?$FieldMap[$Field]:$Field);
> }
>
> But I've just spent a while tracking down a bug where someone mapped A
> to B and then someone else mapped B to C.
>
> I'm thinking of changing the return to...
>
> return isset($FieldMap[$Field])?GetMappedField($FieldMap[$Field]):$Field);
>
> ...but I'm worried about the recursion. (Which isn't a strength of mine)
>
> I don't THINK I need to worry about circular mappings... but I'm not
> sure how to check for it if I did...
>
> Any suggestions? Thanks!
>
> Matt
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
> I don't THINK I need to worry about circular mappings... but I'm not
> sure how to check for it if I did...
>
> Any suggestions? Thanks!
Would the following work? It avoids recursion entirely and also checks for
circular mappings. You can plug in your own code where the comments are to do
whatever is appropriate when a circular mapping is detected.
function GetMappedField($Field)
{
$OriginalField = $Field;
while (isset($FieldMap[$Field]) {
$Field = $FieldMap[$Field];
if ($Field === $OriginalField) {
/*
* circular mapping has been detected;
* report an error or explode or whatever
*/
break;
}
}
return $Field;
}
Ben
--- End Message ---
--- Begin Message ---
> while (isset($FieldMap[$Field]) {
Oops, left out the final close-parenthesis. I always do that with isset() for
some reason.
Ben
--- End Message ---
--- Begin Message ---
Is there a more efficient way to write the following?
<?php $result = mysql_query("SELECT priceList FROM catalog WHERE
itemid='ABC1'",$db);
printf("<i>List: <s>%s</s></i><br />\n", money_format('$%i',
mysql_result($result,0,"priceList"))); ?>
I have many products per page and this code pulls the list price and
formats it. It works fine, but I'd like to know if I can shorten it.
I've looked at number_format over money_format and it's a little
shorter, but not by much. Are there better options than printf and
mysql_result for my use?
Thanks,
Frank
--- End Message ---
--- Begin Message ---
Hi,
> I have many products per page and this code pulls the list price and
> formats it. It works fine, but I'd like to know if I can shorten it.
Personally, I would advise against trying to cram as much as possible
into the least amount of space as possible, and instead going for
verbosity/readability. It will help when you come back to re-read it
in X months.
--
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 25th July)
Lots of PHP and Javascript code - http://www.phpguru.org
--- End Message ---
--- Begin Message ---
On 07/30/2009 10:15 AM, Ashley Sheridan wrote:
On Thu, 2009-07-30 at 07:12 -0700, Christoph Boget wrote:
>>
You could email it to me, which I presume is better if you replied
back just to me and not the list?
Just copying the list back on in this one now. I don't know of any
places that you could upload a file to off the top of my head. Anyone
have any links?
Just google "upload file"; there are a bunch of sites that do this to
choose from.
(I've never used any so I can't recommend one over the others)
--- End Message ---
--- Begin Message ---
Hi all
I have start a shell script and I want to use ncurses.
It was a quite difficulty to get it working, but now I'm done to start
to develop.
I have already search on sf.net and phpclasses and found a couple, but
I'm looking more stable or with a better OO design.
Do you know any set of classes that handle ncurses easily?
--
Martin Scotta
--- End Message ---
--- Begin Message ---
Hi all,
I have the following segment of XML:
<BookingReference ReferenceSource="api">165432 </BookingReference>
Now I want to get the value of the BookingReference where the
ReferenceSource = "api". In other words I want to get the value 165432.
I have the following code:
$ItemConfirmationReference2 = $xpath->query('BookingReference
ReferenceSource' , $Element);
$ItemConfirmationReference =
trim($ItemConfirmationReference2->item(0)->textContent);
The $Element variable passes the node that contains the BookingReference
node.
The tricky part for me is the ="api" part.
Thanks in advance.
A
--- End Message ---
--- Begin Message ---
Just testing message
Miller, Terion napsal(a):
> Yep I forgot about escaping the $
>
>
>
> On 7/29/09 10:51 AM, "Ford, Mike" <m.f...@leedsmet.ac.uk> wrote:
>
>> -----Original Message-----
>> From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
>> Sent: 29 July 2009 16:36
>>
>> Ok in my output to Quark I need to have $P printed to the page like
>> this:
>>
>> <@$p>2118 S. Campbell Ave
>>
>> So in my php which is going to be grabbing this info and formatting
>> it for
>> the Quark....isn't echoing that "$p" all I get is the <@>
>>
>> I have tried several things:
>>
>> $p = $p
>>
>> $p = print("$p")
>
> "$p" is trying to interpolate the value of the variable $p -- if you had full
> error reporting turned on, you would see a nonexistent variable error. Once
> more, there are several things you can do, of which the two most obvious are:
>
> * Use single quotes: echo '$p';
>
> * Use a backslash: echo "\$p";
>
>
> Cheers!
>
> Mike
> --
> Mike Ford,
> Electronic Information Developer, Libraries and Learning Innovation,
> Leeds Metropolitan University, C507, Civic Quarter Campus,
> Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
> Email: m.f...@leedsmet.ac.uk
> Tel: +44 113 812 4730
>
>
>
>
>
> To view the terms under which this email is distributed, please go to
> http://disclaimer.leedsmet.ac.uk/email.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--- End Message ---
--- Begin Message ---
I'm sorry for this post. It's only testing. Thanks for understand.
--- End Message ---