php-general Digest 27 Dec 2007 23:27:02 -0000 Issue 5203

Topics (messages 266291 through 266312):

Re: Match for titles using pregexp
        266291 by: Robert Cummings
        266292 by: OOzy Pal
        266293 by: Robert Cummings

Re: control browser with <a href> tag
        266294 by: Hiep Nguyen
        266295 by: Daniel Brown
        266296 by: Andrés Robinet

vim/php color scheme
        266297 by: OOzy Pal
        266298 by: Nathan Nobbe
        266299 by: Daniel Brown
        266301 by: OOzy Pal
        266302 by: Nathan Nobbe
        266304 by: Daniel Brown
        266309 by: OOzy Pal
        266310 by: Daniel Brown
        266311 by: OOzy Pal

fopen() for http:// sometimes working, sometimes not
        266300 by: Albert Wiersch
        266303 by: Daniel Brown
        266305 by: Albert Wiersch
        266306 by: Albert Wiersch
        266307 by: Daniel Brown
        266308 by: Daniel Brown
        266312 by: Albert Wiersch

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 ---
On Thu, 2007-12-27 at 11:27 +0300, OOzy Pal wrote:
> more words/chars[<a href="#c_1" id="ids_1"  title="Hello">2</a>]more 
> words/chars
> 
> How can I match for the title. In this case the word Hello using regexp?

<?php

$text = 'more words/chars[<a href="#c_1" id="ids_1"
title="Hello">2</a>]more words/chars';

$title = null;
if( preg_match( '/title="([^"]*)"/Umi', $text, $bits ) )
{
    $title = $bits[1];
}
 
echo 'Title: '.$title."\n";

?>

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 12:40 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> On Thu, 2007-12-27 at 11:27 +0300, OOzy Pal wrote:
> > more words/chars[<a href="#c_1" id="ids_1"  title="Hello">2</a>]more 
> > words/chars
> >
> > How can I match for the title. In this case the word Hello using regexp?
>
> <?php
>
> $text = 'more words/chars[<a href="#c_1" id="ids_1"
> title="Hello">2</a>]more words/chars';
>
> $title = null;
> if( preg_match( '/title="([^"]*)"/Umi', $text, $bits ) )
> {
>     $title = $bits[1];
> }
>
> echo 'Title: '.$title."\n";
>
> ?>
>
> Cheers,
> Rob.
> --
> ...........................................................
> SwarmBuy.com - http://www.swarmbuy.com
>
>     Leveraging the buying power of the masses!
> ...........................................................
>

Wow, worked perfect. Thank you. I just made it (preg_match_all)

more words/chars[<a href="#c_1" id="ids_1"  title="Hello">2</a>]more words/chars

How can I also find the number 2 in (...>2</a...) in the same sentence
and made preg_match_all make array of two items

Array
(
    [0] => Hello
    [1] => 2

)

-- 
OOzy
Ubuntu-Gutsy (7.10)

--- End Message ---
--- Begin Message ---
On Thu, 2007-12-27 at 13:53 +0300, OOzy Pal wrote:
> On Dec 27, 2007 12:40 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > On Thu, 2007-12-27 at 11:27 +0300, OOzy Pal wrote:
> > > more words/chars[<a href="#c_1" id="ids_1"  title="Hello">2</a>]more 
> > > words/chars
> > >
> > > How can I match for the title. In this case the word Hello using regexp?
> >
> > <?php
> >
> > $text = 'more words/chars[<a href="#c_1" id="ids_1"
> > title="Hello">2</a>]more words/chars';
> >
> > $title = null;
> > if( preg_match( '/title="([^"]*)"/Umi', $text, $bits ) )
> > {
> >     $title = $bits[1];
> > }
> >
> > echo 'Title: '.$title."\n";
> >
> > ?>

> Wow, worked perfect. Thank you. I just made it (preg_match_all)
> 
> more words/chars[<a href="#c_1" id="ids_1"  title="Hello">2</a>]more 
> words/chars
> 
> How can I also find the number 2 in (...>2</a...) in the same sentence
> and made preg_match_all make array of two items
> 
> Array
> (
>     [0] => Hello
>     [1] => 2
> 
> )

<?php

$text = 'more words/chars[<a href="#c_1" id="ids_1"
title="Hello">2</a>]more words/chars';

$title = null;
if( preg_match( '#<a[^>]*title="([^"]*)"[^>]*>([^<]*)</a>#Umi', $text,
$bits ) )
{
    $title = $bits[1];
    $content = $bits[2];
}
 
echo 'Title: '.$title."\n"
    .'Content: '.$content."\n";

?>

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
""Warren Vail"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> i have two pages: list.php and update.php
>>
>> list.php will have a hyper link that when click on, it will open a new
>> window for user to update info.  once user clicks update button on
>> update.php page, i want to close update.php and return to list.php.
>> however if user doesn't click update button, i don't want user to go back
>> to list.php.  in other word, freeze up list.php until user closes or
>> clicks update button on update.php.
>>
>> is this possible to do with php?
>
> Yes and no, don't think you intend to, but you may be mixing technologies.
> You refer to hyperlinks, etc, which is web technologies and windows, which
> is not unless you use javascript or ajax.  With PHP you can cause your
> browser to open a new browser by adding target="_blank" to the hyperlink,
> but you cannot easily disable functionality of the old browser (It's still
> open, just usually covered up by the new browser), and if the user clicks
> your hyperlink again a 3rd browser will be opened.  You could name your
> target (target=mypage) which means if the user clicks it a new browser 
> will
> be opened, and if the user clicks the same link again, a 3rd window will 
> not
> be opened, but the page in the "mypage" target will be refreshed.
>
> HTH,
>
> Warren Vail

after read all your replies, i understand and want to redefine the problem.

if user clicks on the hyperlink on list.php page, i want to open a new 
windows for user to update info.  once user clicks update on update.php 
page, i want to close the update.php page automatically and refresh list.php 
page.  i think this is possible.  can someone give me suggestions how to do 
this?

thanks 

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 9:50 AM, Hiep Nguyen <[EMAIL PROTECTED]> wrote:
> if user clicks on the hyperlink on list.php page, i want to open a new
> windows for user to update info.  once user clicks update on update.php
> page, i want to close the update.php page automatically and refresh list.php
> page.  i think this is possible.  can someone give me suggestions how to do
> this?

    Yes.  Ask on a JavaScript list.  Anything like that is done on the
client side (in the browser), which would be handled by JavaScript,
VBScript, or something similar - not PHP.  PHP only handles the server
side of things, before the HTML (or other content) is even passed
through Apache (or whatever HTTP server is running) to serve to the
client.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Hiep Nguyen [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 27, 2007 11:51 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] control browser with <a href> tag
> 
> ""Warren Vail"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >> i have two pages: list.php and update.php
> >>
> >> list.php will have a hyper link that when click on, it will open a
> new
> >> window for user to update info.  once user clicks update button on
> >> update.php page, i want to close update.php and return to list.php.
> >> however if user doesn't click update button, i don't want user to go
> back
> >> to list.php.  in other word, freeze up list.php until user closes or
> >> clicks update button on update.php.
> >>
> >> is this possible to do with php?
> >
> > Yes and no, don't think you intend to, but you may be mixing
> technologies.
> > You refer to hyperlinks, etc, which is web technologies and windows,
> which
> > is not unless you use javascript or ajax.  With PHP you can cause
> your
> > browser to open a new browser by adding target="_blank" to the
> hyperlink,
> > but you cannot easily disable functionality of the old browser (It's
> still
> > open, just usually covered up by the new browser), and if the user
> clicks
> > your hyperlink again a 3rd browser will be opened.  You could name
> your
> > target (target=mypage) which means if the user clicks it a new
> browser
> > will
> > be opened, and if the user clicks the same link again, a 3rd window
> will
> > not
> > be opened, but the page in the "mypage" target will be refreshed.
> >
> > HTH,
> >
> > Warren Vail
> 
> after read all your replies, i understand and want to redefine the
> problem.
> 
> if user clicks on the hyperlink on list.php page, i want to open a new
> windows for user to update info.  once user clicks update on update.php
> page, i want to close the update.php page automatically and refresh
> list.php
> page.  i think this is possible.  can someone give me suggestions how
> to do
> this?
> 
> thanks

Yes, you will need something like this http://www.wildbit.com/labs/modalbox/ or 
a regular javascript popup (window.open).
Modalbox is based on prototype and scriptaculous, but there are other 
lightweight solutions over there too (someone mentioned jQuery and Thickbox I 
think, and there's also a Mootools version called MOOdalbox or something).
This is something you need to program on the client-side (at least most of it), 
so it's not about PHP.

Rob

Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | 
TEL 954-607-4207 | FAX 954-337-2695
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE: bestplace |  
Web: http://www.bestplace.biz | Web: http://www.seo-diy.com

--- End Message ---
--- Begin Message ---
Anyone have a nice color scheme for php syntax highlighting in vim? I
am using elflord and it is nice but the comment color is like the
function color which makes it confusing.


-- 
OOzy
Ubuntu-Gutsy (7.10)

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 11:00 AM, OOzy Pal <[EMAIL PROTECTED]> wrote:

> Anyone have a nice color scheme for php syntax highlighting in vim? I
> am using elflord and it is nice but the comment color is like the
> function color which makes it confusing.
>

torte is my favorite; w/ a dark background.
murphy is runner up (also w/ dark bg).

-nathan

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 11:00 AM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> Anyone have a nice color scheme for php syntax highlighting in vim? I
> am using elflord and it is nice but the comment color is like the
> function color which makes it confusing.

    I do all of my coding in ViM, and I just use the default colors.
The basic scheme is like this:
        * HTML syntax is highlighted outside of the PHP tags
        * PHP tags are purple
        * Comments are dark blue
        * Known functions are turquoise
            L> Function parameters are white, unless they are quoted
or variables
        * Variables are turquoise, with a bronze $
        * Quoted strings are red
        * Operators are bronze
        * Custom functions are white with purple parentheses
        * HEREDOC is white, with the exception of variables (as described above)

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 7:09 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Dec 27, 2007 11:00 AM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> > Anyone have a nice color scheme for php syntax highlighting in vim? I
> > am using elflord and it is nice but the comment color is like the
> > function color which makes it confusing.
>
>     I do all of my coding in ViM, and I just use the default colors.
> The basic scheme is like this:
>         * HTML syntax is highlighted outside of the PHP tags
>         * PHP tags are purple
>         * Comments are dark blue
>         * Known functions are turquoise
>             L> Function parameters are white, unless they are quoted
> or variables
>         * Variables are turquoise, with a bronze $
>         * Quoted strings are red
>         * Operators are bronze
>         * Custom functions are white with purple parentheses
>         * HEREDOC is white, with the exception of variables (as described 
> above)
>
> --
> Daniel P. Brown
> [Phone Numbers Go Here!]
> [They're Hidden From View!]
>
> If at first you don't succeed, stick to what you know best so that you
> can make enough money to pay someone else to do it for you.
>

How can I edit these .vim files to tweak colors. Where are colors defined?

-- 
OOzy
Ubuntu-Gutsy (7.10)

--- End Message ---
--- Begin Message ---
if you want to try out all the colorschemes on your system you can
do so pretty quickly and easily, with the following keystrokes:

   1. Esc
   2. (type) :colorscheme
   3. space
   4. tab through the available colorschemes

-nathan

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 12:02 PM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> How can I edit these .vim files to tweak colors. Where are colors defined?

    [This example assumes your version is 6.3 and it's a default
installation.  YMMV. -DPB]

    Color schemes and themes are in:
        /usr/share/vim/vim63/colors/

    Syntax highlighting definition files are in:
        /usr/share/vim/vim63/syntax/

    To edit the PHP syntax highlighting definition file, open:
        /usr/share/vim/vim63/syntax/php.vim

    In there, you'll find lines such as this:
        syn keyword     phpFunctions    utf8_decode utf8_encode
xml_error_string xml_get_current_byte_index
xml_get_current_column_number xml_get_current_line_number
xml_get_error_code xml_parse_into_struct xml_parse
xml_parser_create_ns xml_parser_create xml_parser_free
xml_parser_get_option xml_parser_set_option
xml_set_character_data_handler xml_set_default_handler
xml_set_element_handler xml_set_end_namespace_decl_handler
xml_set_external_entity_ref_handler xml_set_notation_decl_handler
xml_set_object xml_set_processing_instruction_handler
xml_set_start_namespace_decl_handler
xml_set_unparsed_entity_decl_handler contained

    Those define how each string (keyword) should be classified.  In
the above example, `xml_parso_into_struct` would be classified as
`phpFunctions`.  Further down, you'll see lines like these:

        HiLink         phpStringDouble        String
        HiLink         phpNumber      Number
        HiLink         phpFloat       Float
        HiLink         phpMethods     Function
        HiLink         phpFunctions   Function
        HiLink         phpBaselib     Function

    Notice that `phpFunctions` is an alias to `Function`.

    Now check through the files in the themes directory, and you'll
see that (some) have colors and styles defined for Function (some are
re-aliased as `Identifier`, if memory serves correctly).  Take a few
hints from those files, and you should be able to write your own from
scratch.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
Daniel,

Sweet! Mine is version 7.x but I got it. I will check under vim7x. I
post if I have further questions.

Thank you

On Dec 27, 2007 8:20 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Dec 27, 2007 12:02 PM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> > How can I edit these .vim files to tweak colors. Where are colors defined?
>
>     [This example assumes your version is 6.3 and it's a default
> installation.  YMMV. -DPB]
>
>     Color schemes and themes are in:
>         /usr/share/vim/vim63/colors/
>
>     Syntax highlighting definition files are in:
>         /usr/share/vim/vim63/syntax/
>
>     To edit the PHP syntax highlighting definition file, open:
>         /usr/share/vim/vim63/syntax/php.vim
>
>     In there, you'll find lines such as this:
>         syn keyword     phpFunctions    utf8_decode utf8_encode
> xml_error_string xml_get_current_byte_index
> xml_get_current_column_number xml_get_current_line_number
> xml_get_error_code xml_parse_into_struct xml_parse
> xml_parser_create_ns xml_parser_create xml_parser_free
> xml_parser_get_option xml_parser_set_option
> xml_set_character_data_handler xml_set_default_handler
> xml_set_element_handler xml_set_end_namespace_decl_handler
> xml_set_external_entity_ref_handler xml_set_notation_decl_handler
> xml_set_object xml_set_processing_instruction_handler
> xml_set_start_namespace_decl_handler
> xml_set_unparsed_entity_decl_handler contained
>
>     Those define how each string (keyword) should be classified.  In
> the above example, `xml_parso_into_struct` would be classified as
> `phpFunctions`.  Further down, you'll see lines like these:
>
>         HiLink         phpStringDouble        String
>         HiLink         phpNumber      Number
>         HiLink         phpFloat       Float
>         HiLink         phpMethods     Function
>         HiLink         phpFunctions   Function
>         HiLink         phpBaselib     Function
>
>     Notice that `phpFunctions` is an alias to `Function`.
>
>     Now check through the files in the themes directory, and you'll
> see that (some) have colors and styles defined for Function (some are
> re-aliased as `Identifier`, if memory serves correctly).  Take a few
> hints from those files, and you should be able to write your own from
> scratch.
>
> --
>
> Daniel P. Brown
> [Phone Numbers Go Here!]
> [They're Hidden From View!]
>
> If at first you don't succeed, stick to what you know best so that you
> can make enough money to pay someone else to do it for you.
>



-- 
OOzy
Ubuntu-Gutsy (7.10)

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 2:27 PM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> Daniel,
>
> Sweet! Mine is version 7.x but I got it. I will check under vim7x. I
> post if I have further questions.
>
> Thank you

    You're welcome, but try to keep non-PHP-related questions on their
respective lists.  This one is really only for PHP questions, I just
thought that particular question and answer would benefit the PHP
developer community in the archives.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 10:32 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Dec 27, 2007 2:27 PM, OOzy Pal <[EMAIL PROTECTED]> wrote:
> > Daniel,
> >
> > Sweet! Mine is version 7.x but I got it. I will check under vim7x. I
> > post if I have further questions.
> >
> > Thank you
>
>     You're welcome, but try to keep non-PHP-related questions on their
> respective lists.  This one is really only for PHP questions, I just
> thought that particular question and answer would benefit the PHP
> developer community in the archives.
>
> --
>
> Daniel P. Brown
> [Phone Numbers Go Here!]
> [They're Hidden From View!]
>
> If at first you don't succeed, stick to what you know best so that you
> can make enough money to pay someone else to do it for you.
>

Sure.

Sorry for mixing up things.

-- 
OOzy
Ubuntu-Gutsy (7.10)

--- End Message ---
--- Begin Message ---
I noticed my script at http://onlinewebcheck.com was sometimes (fairly 
often) failing to open some URLs that users have entered. fopen() returns 
false very quickly, but when tried again with the same URL, sometimes it 
works. What would cause this behavior? Why does fopen() occasionally fail to 
open valid http addresses but works at other times?

-- 
Albert Wiersch

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 11:31 AM, Albert Wiersch <[EMAIL PROTECTED]> wrote:
>
> I noticed my script at http://onlinewebcheck.com was sometimes (fairly
> often) failing to open some URLs that users have entered. fopen() returns
> false very quickly, but when tried again with the same URL, sometimes it
> works. What would cause this behavior? Why does fopen() occasionally fail to
> open valid http addresses but works at other times?

    Are the URLs being passed to fopen() properly escaped?  Are they
valid, complete with http:// placed before the domain?  Try keeping a
log of all URLs entered for a bit, and see which ones fail.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
""Daniel Brown"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Dec 27, 2007 11:31 AM, Albert Wiersch <[EMAIL PROTECTED]> 
> wrote:
>
>    Are the URLs being passed to fopen() properly escaped?  Are they
> valid, complete with http:// placed before the domain?  Try keeping a
> log of all URLs entered for a bit, and see which ones fail.

It's not the URL because the same URL will not work one time but will work 
another time.

What needs to be escaped for a URL anyway? I am just changing spaces to 
'%20' now.

I will try upgrading to 5.2.5. I'm using 5.2.3 now.

Thanks,
Albert

--- End Message ---
--- Begin Message ---
Some additional info. It seems I am getting these warnings when it fails:

Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo 
failed: Name or service not known

Warning: fopen(http://wanganda2u.co.uk) [function.fopen]: failed to open 
stream:

Now I have to find out why that is failing some of the time but not other 
times.

-- 
Albert Wiersch
Fix your website: http://onlinewebcheck.com


""Albert Wiersch"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> I noticed my script at http://onlinewebcheck.com was sometimes (fairly 
> often) failing to open some URLs that users have entered. fopen() returns 
> false very quickly, but when tried again with the same URL, sometimes it 
> works. What would cause this behavior? Why does fopen() occasionally fail 
> to open valid http addresses but works at other times?
>
> -- 
> Albert Wiersch 

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 12:57 PM, Albert Wiersch <[EMAIL PROTECTED]> wrote:
> What needs to be escaped for a URL anyway? I am just changing spaces to
> '%20' now.

    Arbitrary code can still be injected unless it's properly
sanitized, but that's beyond the scope here.

    Mainly, make sure quotes (single and double) are being converted.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
On Dec 27, 2007 1:00 PM, Albert Wiersch <[EMAIL PROTECTED]> wrote:
>
> Some additional info. It seems I am getting these warnings when it fails:
>
> Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo
> failed: Name or service not known

    That sounds like a DNS resolution error.  If you have Telnet/SSH
or local console access, try doing a dig, traceroute, and ping series
on it.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
""Daniel Brown"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
>    That sounds like a DNS resolution error.  If you have Telnet/SSH
> or local console access, try doing a dig, traceroute, and ping series
> on it.

Hi Daniel,

Yes, I have SSH access. I will keep that in mind. Upgrading to 5.2.5 may 
have addressed this issue though. If not, then I'll concentrate on a 
possible DNS resolution problem.

Albert

--- End Message ---

Reply via email to