php-general Digest 30 Oct 2009 12:51:19 -0000 Issue 6418
Topics (messages 299535 through 299538):
Re: please help with regular expression in preg_replace
299535 by: Jim Lucas
299536 by: Red
Re: dynamic menu with show hide capabilities - understanding possible workflow
299537 by: MEM
How APC Work?
299538 by: Erick Couto
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 ---
Red wrote:
> hello, im not a php developer, i just need to rewrite one php file but having
> problem with understanding syntax of regexp in php.
>
> i need to get domain name from fqdn (for example from $_SERVER['HTTP_HOST'] )
>
> in sed its working well with "s/[^.]*\.//" , but preg_replace behaves weird.
>
>
> http_host is for example hostname.domain.com
>
> <?php
> $host = $_SERVER['HTTP_HOST'];
> exec( "echo $host | sed s/[^.]*\.//", $domain ) ;
> echo "$domain[0]"
> ?>
>
> return "domain.com", but
>
> <?php
> $host = $_SERVER['HTTP_HOST'];
> $domain = preg_replace( '/[^.]*\./' , '', $host) ;
> echo "$domain";
> ?>
>
> return only "com"
>
> i think when this php page get many hits, its not so wise to call sed
> everytime, i would like to ask someone for help how to write preg_replace
> pattern.
>
> thanx
>
> Rene
>
I would add one thing and change another.
<?php
$host = $_SERVER['HTTP_HOST'];
$domain = preg_replace( '/^[^.]+\./' , '', $host) ;
echo $domain;
?>
Adding an additional '^' to the start tells it to start at the beginning.
And changing '*' to a '+'
Jim
--- End Message ---
--- Begin Message ---
Many thanx to Jim and andy for their replies, with Jim`s changes its now
working like in sed. Excuse me for my stupid question, but im old unix/linux
system engineer coding with C , perl and bash, php gave me unpredictable
results in this task. ;-)
so, in final, may be this help some other roundcube users who need one
universal site for many domain access.
this is test page:
<?php
$host = "host.1stdom.com" ;
//$host = "host.2nddom.1stdom.com" ;
$pattern1 = '/[^.]*\./U' ;
$pattern2 = '/^[^.]+\./' ;
exec( "echo $host | sed s/[^.]*\.//", $dom_sed ) ;
$p1_1 = preg_replace( '/[^.]*\./U' , '', $host ) ;
$p1_2 = preg_replace( $pattern1 , '', $host ) ;
$p2_1 = preg_replace( '/^[^.]+\./' , '', $host ) ;
$p2_2 = preg_replace( $pattern2 , '', $host ) ;
echo "$host <br>" ;
echo "dom_sed = $dom_sed[0]<br>" ;
echo "p1_1 = $p1_1 <br> " ;
echo "p1_2 = $p1_2 <br> " ;
echo "p2_1 = $p2_1 <br> " ;
echo "p2_2 = $p2_2 <br> " ;
?>
with result:
host.1stdom.com
dom_sed = 1stdom.com
p1_1 = com
p1_2 = com
p2_1 = 1stdom.com
p2_2 = 1stdom.com
and this is line which i need in roundcube setup:
$rcmail_config['username_domain'] = preg_replace( '/^[^.]+\./' , '',
$_SERVER['HTTP_HOST'] ) ;
many thanks again
Rene
----- Original Message -----
From: "Jim Lucas" <[email protected]>
To: "Red" <[email protected]>
Cc: <[email protected]>
Sent: Friday, October 30, 2009 12:33 AM
Subject: Re: [PHP] please help with regular expression in preg_replace
Red wrote:
hello, im not a php developer, i just need to rewrite one php file but
having problem with understanding syntax of regexp in php.
i need to get domain name from fqdn (for example from
$_SERVER['HTTP_HOST'] )
in sed its working well with "s/[^.]*\.//" , but preg_replace behaves
weird.
http_host is for example hostname.domain.com
<?php
$host = $_SERVER['HTTP_HOST'];
exec( "echo $host | sed s/[^.]*\.//", $domain ) ;
echo "$domain[0]"
?>
return "domain.com", but
<?php
$host = $_SERVER['HTTP_HOST'];
$domain = preg_replace( '/[^.]*\./' , '', $host) ;
echo "$domain";
?>
return only "com"
i think when this php page get many hits, its not so wise to call sed
everytime, i would like to ask someone for help how to write preg_replace
pattern.
thanx
Rene
I would add one thing and change another.
<?php
$host = $_SERVER['HTTP_HOST'];
$domain = preg_replace( '/^[^.]+\./' , '', $host) ;
echo $domain;
?>
Adding an additional '^' to the start tells it to start at the beginning.
And changing '*' to a '+'
Jim
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: MEM [mailto:[email protected]]
> Sent: terça-feira, 27 de Outubro de 2009 12:05
> To: '[email protected]'
> Cc: 'Jim Lucas'; '[email protected]'
> Subject: RE: [PHP] dynamic menu with show hide capabilities -
> understanding possible workflow
>
> >Think of it a bit like an online shop selling operating systems:
> >
> >1) All the main OS's you sell are on the front page - Linux, MacOS &
> Windows
> >2) User clicks on Linux, and is taken to the url /products/linux and
> they are shown all the Linux OS's on offer >(Fedora, SuSe, Ubuntu,
> Knoppix, etc)
> >3) User clicks on Fedora and is taken to the URL
> /products/linux/fedora and they are shown all the versions of Fedora
> >up to 11
> >4) etc
> >
> >The URL belies what section you are on, which makes it easy for the
> user to remember, and easy for you to extract >information from to know
> exactly where the user is. Obviously in the above URLs I'm assuming
> mod_rewrite is being >used.
> >Thanks,
> >Ash
> >http://www.ashleysheridan.co.uk
>
>
>
> Thanks a lot! Really.
> I will now start coding based on all this information and see what I
> will get.
>
> I'm sure that the designer will kill me later, by telling me...
> couldn't we just... fade in this a little bit... Ahhrrggg!!!
>
>
> Regards,
> Márcio
Hello once again,
I have take my time to think on this for a while.
And I end up on the W3C recommendations about URIs:
In a phrase: Keep it semantic, lifetime, and short.
Several questions arise at this moment:
I was having a url like this:
http://www.mysite.com/c_mycontroller/method/1/3/4/54
Where the numbers where Id's of categories or products. Well...
this could be as far as we can get from the W3C recommendations. :s
So, let's say I short those urls to names, and I remove/hide(?)
from the URL the controller and method information's.
We could end up on something like this:
http://www.mysite.com/categoryname/subcategoryname/subsubcategoryname/productname/
It's more semantic. But what if we have, 4 subcategories for example? This
could get quite long.
A possible solution to this, is to have something like this:
http://www.mysite.com/categoryname/subcategoryname/productname
In a way that we always get no more than 3 URI segments.
So, if the user navigates to a sub sub sub sub level on the hierarchy, the
address could be:
http://www.mysite.com/categoryname/subsubsubsubcategoryname/productname
1) What are your thoughts on this? Should I follow this track on your opinions?
2) In order to be semantic, I intend to pass through the URI segments, NOT the
Category id's but the Category names.
This will bring two issues (at least):
2.1) - I need to query the database, not by ID but by Name. (I'm not sure if
they always be unique, I'm not sure if I will have a performance issue). As a
note: This is a VERY little website. Nothing too fancy.
2.2) I will grab the categories name from the database, and build the URL with
those names, however, some category names will have INVALID chars, like á, ç,
spaces... etc... What would be the best way of doing this? Having a new column
on the database categories table with a "slug" field? Or, grab the category
name, and prepare that name to be "url friendy" using a function for that? If
it's possible to answer, where on a MVC structure would this function be?
Regards,
Márcio
--- End Message ---
--- Begin Message ---
Hi,
How *APC* – Alternative *PHP* Cache store data on cache? memory? file
system?
i´m developing a PHP application with many requests for read/write on APC
stored variables,
im scared with future slow down with many IO on APC.
Thanks,
Erick Couto
--- End Message ---