RE: [PHP] Formatting phone numbers?

2004-04-17 Thread Andy Crain
Jay,

 Here is a little more of the larger function with comments (more
 comments than code, which is never a Bad Thing [tm]). I am only showing
 the handling for two basic types of telephone numbers with explanation
 for additional verification which we would typically use, since we have
 those resources available.

Great. Thanks very much.
Andy

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



RE: [PHP] Formatting phone numbers?

2004-04-16 Thread Andy Crain
Good stuff.

 [stuff you may not need]
 This is a boiled down version of a longer function that counts string
 lengths to determine how many dashes might need to be added. Let's say
 you have the area code in the number, like 2108765432. Being a ten digit
 number with a recognizable area code we can then add a portion to the
 function to add the two needed dashes, making the number more readable.
 [/stuff]

I'd love to see that larger function, if you care to share.
Andy

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



RE: [PHP] Re: IPTC image comments utility

2004-02-12 Thread Andy Crain
This might help:
http://pear.php.net/package/Image_IPTC
Andy

 -Original Message-
 From: Paul Furman [mailto:[EMAIL PROTECTED]
 Sent: Thursday, February 12, 2004 7:36 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: IPTC image comments utility
 
 OK this looks like the thing:
 http://multipart-mixed.com/photo/iptc.html
 It's a perl module. Can I use that in PHP?
 
 Paul Furman wrote:
 
  Does anyone know of a utility for WRITING or at least reading IPTC data
  in images with PHP? I found lots of EXIF utilities and did an
  experimental thing with that. PHP even has a built in EXIF reader but
  the only IPTC utilities I've found are expensive ActiveX or Delphi
  components and I don't even know if those could be operated by PHP. THe
  one I used worked at a command line  I just did a shell command with a
  constructed syntax.
 
  Here's some stuff I dug up:
 
 
  COMIPTC 900 Euros
  http://www.j2s.net/EN/Products/comiptc.html
  Works with Visual Basic, ASP or PHP
  Matches Photoshop format
  Works on JPEG, TIFF, PSD
 
  TIPTC Delphi $566.60
  http://www.atom5.com/Development/Components-Libraries-for-Delphi/tiptc-
 delphi-component-to-read-and-write-iptc-data-from-jpeg-tiff-files-
 2620.html
 
  JPEG/TIFF
  source code in pure Delphi code
 
  Atalasoft dotImage $329-$999
  http://www.atalasoft.com/Components/dotImage
  C# ActiveX component .NET compatible
  many features
 
  AiS EXIF ActiveX $25-$99 (server)
  http://www.watermarker.com/exif-iptc-gps/
  ActiveX component for Win9X/ME/NT/2k/XP
  Visual Basic, Delphi, C++, ASP, ASPX, PHP.
  EXIF, IPTC for JPEG/TIFF
 
 --
 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



RE: [PHP] Singleton Was: [PHP] OO parent/child relationship

2003-10-07 Thread Andy Crain
One quick thought:

You might want to add the following to your if statement:
else {
$this-_cache[$key] = new $key;
return $this-_cache[$key];
}


Andy

 -Original Message-
 From: Gerard Samuel [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 06, 2003 5:36 PM
 To: 'PHP List'
 Subject: [PHP] Singleton Was: [PHP] OO parent/child relationship
 
 Gerard Samuel wrote:
 
  Andy Crain wrote:
 
  This all seems like a perfect case for the singleton pattern. See
  http://www.phppatterns.com/index.php/article/articleview/6/1/1/ and
  http://www.phppatterns.com/index.php/article/articleview/75/1/1/
  Andy
 
  Im currently trying to wrap the brain around the Singleton Registry
  article.
  Wish me luck :)
 
 http://www.trini0.org/index.php
 This is based on work seen at
 http://www.phppatterns.com/index.php/article/articleview/75/1/1/
 Yes yes, I know.  It uses $GLOBALS, (OO Sin).  Father forgive me
  From the article, Im getting lost with the reason/meaning/purpose of
 the instance() method.
 If anyone can clarify it for me, and let me know if my example would
 need something like it.
 So if you care to critique it, feel free, Ill try not to be hurt ;)
 Thanks
 
 --
 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



RE: [PHP] OO parent/child relationship

2003-10-06 Thread Andy Crain
This all seems like a perfect case for the singleton pattern. See
http://www.phppatterns.com/index.php/article/articleview/6/1/1/ and
http://www.phppatterns.com/index.php/article/articleview/75/1/1/
Andy

 -Original Message-
 From: Evan Nemerson [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 06, 2003 2:07 AM
 To: Robert Cummings; Curt Zirzow
 Cc: PHP List
 Subject: Re: [PHP] OO parent/child relationship
 
 Aye. PHP already reserves function names prepended with __ as magic.
But
 really one could make this argument ad infinitum. If everyone wants to
 start
 their variables with a *insert random character here*, *grin*
 
 IMHO it's good advice to prepend global vars with '__' or something.
I
 usually prepend my global vars with the application name. For
instance,
 $wiki_DSN, $wiki_title, $wiki_authors, etc.
 
 
 
 On Sunday 05 October 2003 09:58 pm, Robert Cummings wrote:
  On Mon, 2003-10-06 at 00:48, Curt Zirzow wrote:
   On the global topic, I would suggest establishing a standard
   naming convention for your common globals that are used, I do
   something like:
 $__object_something__;
  
   With your global var I can see myself writing something that will
   overwrite that $class_ref, Like say if I'm handling something that
   has to do with referee's in school classes :)  Preceeding the
   global vars with '__' or something will keep the namespace
clashing
   cases down to a minimum.
 
  But if everyone fallows your advice for using __ as a prefix...
*grin*.
 
  Rob.
 
 --
 Evan Nemerson
 [EMAIL PROTECTED]
 
 --
 To achieve adjustment and sanity and the conditions that follow from
 them, we
 must study the structural characteristics of this world first and,
then
 only,
 build languages of similar structure, instead of habitually ascribing
to
 the
 world the primitive structure of our language.
 
 -Alfred Korzybski
 
 --
 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



RE: [PHP] Re: rich text editing

2003-08-22 Thread Andy Crain
The only problem in doing so, for me at least, is in editing text
created by htmlarea. Nonsupported users who get a normal textarea
pre-loaded with html generated by htmlarea could break tags, etc., on
updates. I wrote a class I use to work around this by: determining which
type of textarea they'll get (wysiwyg htmlarea or plain textarea), and
if they're using a plain textarea and editing html, all html except for
bold, italics and underline tags are replaced with markers. The plain
textarea user then can add standard bb style tags, [b], [i], etc., then
on submit the bb tags will be converted to html, and the original html
will be added back in, properly nested, etc. If you'd like to use it,
I'd be happy to email it. I'm sure it could use a few extra sets of
eyes.
Andy

 -Original Message-
 From: Nelson Rodríguez-Peña Alarcón [mailto:[EMAIL PROTECTED]
 Sent: Thursday, August 21, 2003 6:46 PM
 To: Redmond Militante
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] Re: rich text editing
 
 Hi,
 
 Redmond Militante wrote:
  
  (...) what do people generally do when using an activex rich text
  editor and the user is using a non supported browser?
 
 You can display a textarea. It'd allow users to edit/add content in a
 simpler, less powered way.
 
 --
 regards,
 
 
 Nelson Rodríguez-Peña A.
 Diseño y Desarrollo Web y Multimedia
 
 
 
 --
 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



RE: [PHP] OO function overloading?

2003-08-14 Thread Andy Crain
Or, if you'd rather not use an experimental extension, there's this hack
(learned from http://www.phpbuilder.com/columns/luis2420.php3):

class MyClass{

function MyClass(){
$name = 'MyClass' . func_num_args();
$this-$name();
}

function MyClass1($x){
}

function MyClass2($x,$y){
}

function MyClass3($x,$y,$z){
}

//etc.
}

Andy
 -Original Message-
 From: Greg Beaver [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 06, 2003 1:09 AM
 To: Jean-Christian Imbeault
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] OO function overloading?
 
 Indeed it is a hack, but not for PHP 5, the extension has become part
of
 the core, and does not require that odd little overload() call :)
 
 Greg
 
 Jean-Christian Imbeault wrote:
 
  Greg Beaver wrote:
 
 
 This statement isn't entirely correct, overloading is possible with
the
 overload extension.
 
 
  True. Nice work. But still a hack in my mind :) (though a *very*
clean
  hack).
 
  Jean-Christian Imbeault
 
 
 
 --
 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] question on preg_replace()

2003-02-26 Thread Andy Crain
I'm having a problem figuring out how to prevent preg_replace() from
replacing substrings when one element of the pattern array matches a
portion of  a string that would match a subsequent value in the pattern
array.

 

Say I have an two arrays:

find = Array

(

[0] = 'fred'

[1] = 'tom'

[2] = 'frederick'

)

replace = Array

(

[0] = 'person1'

[1] = 'person2'

[2] = 'person3'

)

and a string $string = 'fred knows tom who knows frederick'. So the
string contains an instance of each $find value, and I'd like to replace
each one with its corresponding $replace value.

 

The problem is that preg_replace() changes 'frederick' to 'person1erick'
before even getting to find[2] ('frederick'), which at this point won't
find anything to replace, and I'm left with 'person1 knows person2 who
knows person1erick' when what I want to end up with is 'person1 knows
person2 knows person3.'

 

Also, the actual values in the $find array are not names but strings
representing each unique combination of HTML tags in $string (such as
'br', 'b', 'bru', so that the u here would be left over
unmatched). It seems to me that my only option is to write a function to
sort $find in reverse order by length, so that the longer strings are
replaced first. Or am I missing something obvious?

 

Thanks in advance,

Andy



RE: [PHP] preg_match question: locating unmatched HTML tags

2003-02-22 Thread Andy Crain
John,
Thanks. I'm considering that, but the application I'm working on is for
a small intranet that will be for only a small group of supervised
users, so vulnerability isn't such a large concern.
Andy

 -Original Message-
 From: John W. Holmes [mailto:[EMAIL PROTECTED]
 Sent: Saturday, February 22, 2003 1:06 AM
 To: 'Andy Crain'; [EMAIL PROTECTED]
 Subject: RE: [PHP] preg_match question: locating unmatched HTML tags
 
  I'm trying to build a regexp that would parse user-supplied text and
  identify cases where HTML tags are left open or are not properly
  matched-e.g., b tags without closing /b tags. This is for a sort
 of
  message board type of application, and I'd like to allow users to
use
  some HTML, but just would like to check to ensure that no stray tags
 are
  input that would screw up the rest of the page's display. I'm new to
  regular expressions, and the one below is as far as I've gotten. If
  anyone has any suggestions, they'd be very much appreciated.
 
 Letting users enter HTML is a bad idea. Even if you only let them use
 b tags, they can still put ONCLICK and mouseover effects for the
bold
 text to screw with your other users.
 
 Use a BB style code, such as [b] for bold, [i] for italics, etc. This
 way, you only match pairs and replace them with HTML and use
 htmlentities on anything else. This way an unmatched [b] tag won't be
 replaced with b and mess up your code.
 
 ---John W. Holmes...
 
 PHP Architect - A monthly magazine for PHP Professionals. Get your
copy
 today. http://www.phparch.com/
 
 
 
 --
 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



RE: [PHP] preg_match question: locating unmatched HTML tags

2003-02-22 Thread Andy Crain
Ernest,
Thanks very much. This is pretty close to what I'm looking for. The only
problem is that it doesn't catch nested tags. For example, some btext
/usome/b text some text makes it through without error since, I
think, preg_match resumes matching at the /b after spotting and then
checking its first match, at b.
Andy

 -Original Message-
 From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED]
 Sent: Saturday, February 22, 2003 5:48 AM
 To: Andy Crain
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] preg_match question: locating unmatched HTML tags
 
 At 03:35 22.02.2003, Andy Crain said:
 [snip]
 My apologies in advance if this too basic or there's a solution
easily
 found out there, but after lots of searching, I'm still lost.
 
 I'm trying to build a regexp that would parse user-supplied text and
 identify cases where HTML tags are left open or are not properly
 matched-e.g., b tags without closing /b tags. This is for a sort
of
 message board type of application, and I'd like to allow users to use
 some HTML, but just would like to check to ensure that no stray tags
are
 input that would screw up the rest of the page's display. I'm new to
 regular expressions, and the one below is as far as I've gotten. If
 anyone has any suggestions, they'd be very much appreciated.
 
 $suspect_tags = b|i|u|strong|em|font|a|ol|ul|blockquote ;
 $pattern = '/(' . $suspect_tags . '[^]*)(.*)(?!\/\1)/Ui';
 if (preg_match($pattern,$_POST['entry'],$matches)) {
//do something to report the unclosed tags
 } else {
echo 'Input looks fine. No unmatched tags.';
 }
 [snip]
 
 Hi,
 
 I don't believe you can create a regular expression to look for
something
 that's NOT there.
 
 I'd take this approach (tested with drawbacks, see below):
 
 function check_tags($text) {
 $suspect_tags = b|i|u|strong|em|font|a|ol|ul|blockquote;
 $re_find = '/\s*(' . $suspect_tags . ').*?(.*)/is';
 
 while (preg_match($re_find,$text,$matches)) {
 // a suspect tag was found, check if closed
 $suspect = $matches[1];
 $text = $matches[2];
 $re_close = '/\s*\/\s*' . $suspect . '\s*?(.*)/is';
 if (preg_match($re_close, $text, $matches)) {
 // fine, found matching closer, continue loop
 $text = $matches[1];
 }
 else {
 // not closed - return to report it
 return $suspect;
 }
 }
 return null;
 }
 
 $text = EOT
 This text contains  font
 size=+4  an
 unclosed suspect /finttag.
 
 EOT;
 
 $tag = check_tags($text);
 if ($tag) echo Unmatched: \$tag\\n;
 else echo Perfect!\n;
 
 The drawbacks: This approach is softly targeted at unintended typos,
such
 as in the example text. It won't catch deliberate attacks, such as
Blindtext font color=redfont size=+22Hehe I've got you/font
 because it is missing the second font opener. To catch these attacks
you'd
 need to build a source tree of the text in question.
 
 HTH,
 
 --
O Ernest E. Vogelsinger
(\)ICQ #13394035
 ^ http://www.vogelsinger.at/
 
 
 
 --
 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



RE: [PHP] preg_match question: locating unmatched HTML tags

2003-02-22 Thread Andy Crain
Good point, and I might end up doing just that if I can't find a
solution. The problem is that I'm considering using for some forms a
textarea wysiwyg replacement (e.g.,
http://www.interactivetools.com/products/htmlarea/ or
http://www.siteworkspro.com) that results in HTML output. And I wanted
to check the output of that to make sure there aren't any extraneous
tags.
Andy

 -Original Message-
 From: John W. Holmes [mailto:[EMAIL PROTECTED]
 Sent: Saturday, February 22, 2003 5:04 PM
 To: 'Andy Crain'; [EMAIL PROTECTED]
 Subject: RE: [PHP] preg_match question: locating unmatched HTML tags
 
 Well, like someone else said, it's hard to look for and match stuff
that
 isn't there. In addition to the security benefit, it's just easier to
 code something that looks for [b](.*)[/b] and replaces those tags with
 b and /b (or strong and /strong if you want to be technically
 correct).
 
 Honestly, if you've got a small group of people like you say then just
 teach them HTML so they don't make mistakes like this. Or provide a
 preview mode so they can double check their work.
 
 ---John W. Holmes...
 
 PHP Architect - A monthly magazine for PHP Professionals. Get your
copy
 today. http://www.phparch.com/
 
  -Original Message-
  From: Andy Crain [mailto:[EMAIL PROTECTED]
  Sent: Saturday, February 22, 2003 4:54 PM
  To: [EMAIL PROTECTED]
  Subject: RE: [PHP] preg_match question: locating unmatched HTML tags
 
  John,
  Thanks. I'm considering that, but the application I'm working on is
 for
  a small intranet that will be for only a small group of supervised
  users, so vulnerability isn't such a large concern.
  Andy
 
   -Original Message-
   From: John W. Holmes [mailto:[EMAIL PROTECTED]
   Sent: Saturday, February 22, 2003 1:06 AM
   To: 'Andy Crain'; [EMAIL PROTECTED]
   Subject: RE: [PHP] preg_match question: locating unmatched HTML
tags
  
I'm trying to build a regexp that would parse user-supplied text
 and
identify cases where HTML tags are left open or are not properly
matched-e.g., b tags without closing /b tags. This is for a
 sort
   of
message board type of application, and I'd like to allow users
to
  use
some HTML, but just would like to check to ensure that no stray
 tags
   are
input that would screw up the rest of the page's display. I'm
new
 to
regular expressions, and the one below is as far as I've gotten.
 If
anyone has any suggestions, they'd be very much appreciated.
  
   Letting users enter HTML is a bad idea. Even if you only let them
 use
   b tags, they can still put ONCLICK and mouseover effects for the
  bold
   text to screw with your other users.
  
   Use a BB style code, such as [b] for bold, [i] for italics, etc.
 This
   way, you only match pairs and replace them with HTML and use
   htmlentities on anything else. This way an unmatched [b] tag won't
 be
   replaced with b and mess up your code.
  
   ---John W. Holmes...
  
   PHP Architect - A monthly magazine for PHP Professionals. Get your
  copy
   today. http://www.phparch.com/
  
  
  
   --
   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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match question: locating unmatched HTML tags

2003-02-21 Thread Andy Crain
My apologies in advance if this too basic or there's a solution easily
found out there, but after lots of searching, I'm still lost.

 

I'm trying to build a regexp that would parse user-supplied text and
identify cases where HTML tags are left open or are not properly
matched-e.g., b tags without closing /b tags. This is for a sort of
message board type of application, and I'd like to allow users to use
some HTML, but just would like to check to ensure that no stray tags are
input that would screw up the rest of the page's display. I'm new to
regular expressions, and the one below is as far as I've gotten. If
anyone has any suggestions, they'd be very much appreciated.

Thanks,

Andy

 

 

$suspect_tags = b|i|u|strong|em|font|a|ol|ul|blockquote ;

$pattern = '/(' . $suspect_tags . '[^]*)(.*)(?!\/\1)/Ui';

if (preg_match($pattern,$_POST['entry'],$matches)) {

   //do something to report the unclosed tags

} else {

   echo 'Input looks fine. No unmatched tags.';

}



[PHP] Help with file()--certain URLs causing error

2003-02-05 Thread Andy Crain
Hi,

I'm having trouble using file() to get the text of web pages for an
in-house URL directory and search engine I'm trying to build. I'm using
something along the lines of the following code to take a user-submitted
URL and then fetch the text of the page at that address and store it in
a database for later searching. Most URLs work fine, but really long
ones with long query strings for some reason cause file() to throw up an
error. This URL used in the code below, for example, causes the error
below, but most any other URL works just fine. Any ideas?

Thanks,

Andy

 

//The code

$_POST['url'] =
'http://groups.google.com/groups?hl=enlr=ie=UTF-8oe=UTF-8safe=offth
readm=v0401171cb70ca1615b5a%40%5B192.34.169.24%5Drnum=1prev=/groups%3F
q%3D%252Bphp%2B%252Breturn%2B%252Bkey%2B%252Bform%26hl%3Den%26lr%3D%26ie
%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26selm%3Dv0401171cb70ca1615b5a%2540%2
55B192.34.169.24%255D%26rnum%3D1/';

$_POST['url'] = eregi_replace('http://','',$_POST['url']);

$_POST['url'] = eregi_replace('/$','',$_POST['url']);

$full_url = 'http://' . $_POST['url'] . '/';

 

if(!$body = file($full_url)){

   //echo an error message

} else {

   echo $body;

}

 

Causes:

Warning:
file(http://groups.google.com/groups?hl=enlr=ie=UTF-8oe=UTF-8safe=o
ffthreadm=v0401171cb70ca1615b5a%40%5B192.34.169.24%5Drnum=1prev=/grou
ps%3Fq%3D%252Bphp%2B%252Breturn%2B%252Bkey%2B%252Bform%26hl%3Den%26lr%3D
%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26selm%3Dv0401171cb70ca1615b5a%2
540%255B192.34.169.24%255D%26rnum%3D1/) - No error in c:\program
files\nusphere\apache\htdocs\newslogic_dev\url_directory\test.php on
line 11




[PHP] Returning a value from a recursive function

2003-01-22 Thread Andy Crain
Everyone,

I'm stumped by this, even after searching the archives and the web,
although I admit the solution likely is something very obvious.

 

I've written a function to build a string of breadcrumb links for a
web site directory similar to Yahoo, etc. It queries a categories table
recursively until it reaches the root category, building a string of
categories from the current category all the way back up to root. The
function seems to work fine if I output directly from it using echo, but
if I instead try to return the string to the global scope and then echo
it, I get nothing. The line where I use echo/return is indicated below.

Thanks,

Andy

 

function breadcrumbs($category_id=0,$mode='linked'){

   global $id_array,$name_array;

 

   static $counter = 0;

 

   if ($category_id == 0) {

   //once we're down to the root, build a return string

   if ($mode == 'linked') {

  $output = 'A HREF=' . $_SERVER['PHP_SELF'] . 'HOME/A';

   } else {

  $output = 'HOME';

   }

   while($counter  0){

   if ($mode == 'linked') {

  $output .= '  A HREF=' . $_SERVER['PHP_SELF'] .
'?category_id=' . array_pop($id_array) .  '' . array_pop($name_array)
. '/A';

   } else {

  $output .= '  ' . array_pop($name_array);

   }

   $counter--;

   }

   return $output; /*HERE: IF I SUBSTITUTE ECHO FOR
RETURN, EVERYTHING WORKS; BUT WITH RETURN, IT DOESN'T WORK*/

   } else {

   $sql = 'SELECT category_id, parent_cat, category_name FROM
web_categories WHERE category_id = ' . $category_id;

   $result = safe_query($sql);

   while($query_data = mysql_fetch_assoc($result)){

   $id_array[$counter] = $query_data['category_id'];

   $name_array[$counter] = $query_data['category_name'];

   //now, move one step up and make the current category the
previous parent

   $category_id = $query_data['parent_cat'];

   $counter++;

   breadcrumbs($category_id,$mode);

   }

   }

}

 

$show = breadcrumbs(9);

echo $show;




RE: [PHP] Returning a value from a recursive function

2003-01-22 Thread Andy Crain
Thanks very much, Brian.
Your response helped me find the answer. On the recursive call to
breadcrumbs(), the function wasn't actually returning anything to
itself. I replaced breadcrumbs() with return breadcrumbs() and
everything now works.

 -Original Message-
 From: Brian T. Allen [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, January 22, 2003 4:47 PM
 To: 'Andy Crain'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Returning a value from a recursive function
 
 I think it will work if you return true, and just modify the global
 variable (not try to output it).
 
 Then output it (or capture it to begin with ($total_count =
 OneHundred();) after the function is called.
 
 You could also pass the variable, rather than making it global
 (OneHundred(0) initially, and OneHundred($count) from within the
 function).
 
 For instance:
 
 ?php
 
 function OneHundred(){
   global $count;
 
   if($count  100){
 $count++;
 OneHundred();
   }
 
 return true;
 }
 
 OneHundred();
 
 echo $count;
 
 ?
 
 
 Hope that helps,
 Brian
 
  -Original Message-
  From: Andy Crain [mailto:[EMAIL PROTECTED]]
  Sent: Wednesday, January 22, 2003 1:23 PM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Returning a value from a recursive function
 
 
  Everyone,
 
  I'm stumped by this, even after searching the archives and the web,
  although I admit the solution likely is something very obvious.
 
 
 
  I've written a function to build a string of breadcrumb links for
a
  web site directory similar to Yahoo, etc. It queries a
  categories table
  recursively until it reaches the root category, building a string of
  categories from the current category all the way back up to root.
The
  function seems to work fine if I output directly from it
  using echo, but
  if I instead try to return the string to the global scope and
  then echo
  it, I get nothing. The line where I use echo/return is
  indicated below.
 
  Thanks,
 
  Andy
 
 
 
  function breadcrumbs($category_id=0,$mode='linked'){
 
 global $id_array,$name_array;
 
 
 
 static $counter = 0;
 
 
 
 if ($category_id == 0) {
 
 //once we're down to the root, build a return string
 
 if ($mode == 'linked') {
 
$output = 'A HREF=' . $_SERVER['PHP_SELF'] .
'HOME/A';
 
 } else {
 
$output = 'HOME';
 
 }
 
 while($counter  0){
 
 if ($mode == 'linked') {
 
$output .= '  A HREF=' . $_SERVER['PHP_SELF'] .
  '?category_id=' . array_pop($id_array) .  '' .
  array_pop($name_array)
  . '/A';
 
 } else {
 
$output .= '  ' . array_pop($name_array);
 
 }
 
 $counter--;
 
 }
 
 return $output; /*HERE: IF I SUBSTITUTE ECHO FOR
  RETURN, EVERYTHING WORKS; BUT WITH RETURN, IT DOESN'T WORK*/
 
 } else {
 
 $sql = 'SELECT category_id, parent_cat, category_name FROM
  web_categories WHERE category_id = ' . $category_id;
 
 $result = safe_query($sql);
 
 while($query_data = mysql_fetch_assoc($result)){
 
 $id_array[$counter] = $query_data['category_id'];
 
 $name_array[$counter] = $query_data['category_name'];
 
 //now, move one step up and make the current category the
  previous parent
 
 $category_id = $query_data['parent_cat'];
 
 $counter++;
 
 breadcrumbs($category_id,$mode);
 
 }
 
 }
 
  }
 
 
 
  $show = breadcrumbs(9);
 
  echo $show;
 
 
 
 
 --
 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




RE: [PHP] Trouble with understanding arrays

2002-10-02 Thread Andy Crain

It looks like your problem is simply in the debug line, where you echo
print_r(array_values($TickersCurrent));
You shouldn't call array_values() before print_r(), since array_values
generates an indexed array of only the values (quotes), not the keys
(tickers), of the supplied array, essentially taking your quotes from
your ticker=quote pairs and replacing the tickers with an index. Just
do print_r($TickersCurrent) and you'll get the desired result.
Hope that helps,
Andy

-Original Message-
From: Christopher J. Crane [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, October 02, 2002 8:16 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Trouble with understanding arrays

I am having problems with arrays. I guess I just don't understand them
all
that well.
I have an simple array of stock tickers. Then for each ticker I go to
Yahoo
to get their current price and try to push the Name of the ticker and
it's
value into an associative array(I think). Then I want to sort the array
so
the the values are in order from highest to lowest, so I can see the
highest
amount as the first position and the lowest as the last position.

Here is my problem; for debuggin purposes I do a
print_r(array_values());
and I get the following for output.
Array
(
[0] = 7.28
[1] = 5.20
[2] = 1.969
[3] = 59.63
[4] = 4.43
)

I am not sure why I am getting this. I guess I expected the numerical
positions to be the keys something like:
Array
(
[ikn] = 7.28
[xrx] = 5.20
[danky] = 1.969
[ibm] = 59.63
[rhat] = 4.43
)

Since I am not getting the results I expected I am not sure if the rest
is
working correctly because I do not know how to access the first position
in
the array, or the last. When I get this working, I will be adding 200
tickers and I would like to get the first 5 and the last 5, expecting
them
to be the highest 5 and the lowest 5 respectively. I hope someone will
take
the time to halp me.

Thank you in advance.

Here is the code I am working on:

$Tickers = array(ikn, xrx, danky, ibm, rhat);
$TickersCurrent = array();

 foreach($Tickers as $Ticker) {
   $LookupUrl =
http://finance.yahoo.com/d/quotes.csv?s=$Tickerf=l1e=.txt;;
   $Current = implode('', file($LookupUrl));
   $Current = rtrim($Current);
   $TickersCurrent[$Ticker]=$Current;
   }

// Done for debuggin only
   print pre\n;
   print_r(array_values($TickersCurrent));
   print /pre\n;


   asort ($TickersCurrent);
   reset ($TickersCurrent);

   echo CTC Indice =  . array_sum($TickersCurrent) . br\n;

   echo The highest Stock is $TickersCurrent[0];






-- 
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