Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Traduction php en perl

4 réponses
Avatar
Maxime
Bonjour,

Je connais très mal Perl, et j'ai besoin de mettre l'équivalent de cette
instruction en php :
<?php echo substr(HTTP_SERVER,11); ?>

Par exemple, cela me retourne mondomaine.fr quand je suis sur le site
h**p://www.mondomaine.fr/rep/monscript.php

Comment faire cela ?

Merci.

Maxime

4 réponses

Avatar
kurtz le pirate
In article <e6rifn$t13$, Maxime wrote:

Bonjour,

Je connais très mal Perl, et j'ai besoin de mettre l'équivalent de cette
instruction en php :
<?php echo substr(HTTP_SERVER,11); ?>

Par exemple, cela me retourne mondomaine.fr quand je suis sur le site
h**p://www.mondomaine.fr/rep/monscript.php

Comment faire cela ?


1) substr(HTTP_SERVER,11) sur
"h**p://www.mondomaine.fr/rep/monscript.php" retourne
"mondomaine.fr/rep/monscript.php" et pas "mondomaine.fr" !


2) sinon en perl ça "marche pareil" :
my $chaine = "h**p://www.mondomaine.fr/rep/monscript.php";
my $souschaine = substr($chaine,11);

$souschaine contient : "mondomaine.fr/rep/monscript.php"
(sans les guillemets bien sur :))


--
klp

Avatar
Maxime

1) substr(HTTP_SERVER,11) sur
"h**p://www.mondomaine.fr/rep/monscript.php" retourne
"mondomaine.fr/rep/monscript.php" et pas "mondomaine.fr" !

2) sinon en perl ça "marche pareil" :
my $chaine = "h**p://www.mondomaine.fr/rep/monscript.php";
my $souschaine = substr($chaine,11);

$souschaine contient : "mondomaine.fr/rep/monscript.php"
(sans les guillemets bien sur :))


Effectivement, j'ai été un peu rapide sur le coup, HTTP_SERVER est la
variable de mon script.
Connais tu l'équivalent de la variable php $HTTP_HOST en perl ?

Merci

Avatar
Paul Gaborit
À (at) Fri, 16 Jun 2006 10:44:39 +0200,
Maxime écrivait (wrote):
Connais tu l'équivalent de la variable php $HTTP_HOST en perl ?


Cela n'a rien de spécifique à Perl. C'est la spécification de
l'interface CGI qui définit cela : un certain nombre d'informations
sont passées au script via des variables d'environnement.

En PHP, ces variables d'environnement sont transformées en variables.

En Perl, pour éviter de 'polluer' l'espace des noms, les variables
d'environnement sont accessibles via la table de hachage %ENV.

Donc, dans le cas d'un script CGI, $ENV{'HTTP_HOST'} devrait contenir
le nom du serveur.

--
Paul Gaborit - <http://perso.enstimac.fr/~gaborit/>
Perl en français - <http://perl.enstimac.fr/>

Avatar
kurtz_le_pirate
Maxime" a écrit dans le message de news:
e6tr1o$l1j$

1) substr(HTTP_SERVER,11) sur
"h**p://www.mondomaine.fr/rep/monscript.php" retourne
"mondomaine.fr/rep/monscript.php" et pas "mondomaine.fr" !

2) sinon en perl ça "marche pareil" :
my $chaine = "h**p://www.mondomaine.fr/rep/monscript.php";
my $souschaine = substr($chaine,11);

$souschaine contient : "mondomaine.fr/rep/monscript.php"
(sans les guillemets bien sur :))


Effectivement, j'ai été un peu rapide sur le coup, HTTP_SERVER est
la variable de mon script.
Connais tu l'équivalent de la variable php $HTTP_HOST en perl ?


vas faire un tour la : http://www.cgi101.com/book/ch3/text.html
je pense que tu vas trouver ton bonheur :))