Essayer d'ouvrir une page externe en utilisant php

  • barry
  • Graduate
  • Graduate
  • Avatar de l’utilisateur
  • Inscription: Jan 28, 2005
  • Messages: 115
  • Loc: scotland
  • Status: Offline

Message Mai 16th, 2009, 12:18 pm

Puis quelqu'un s'il vous plaît dites-moi pourquoi ça marche

Code: [ Select ]
function get_type(){
    $site = fopen('http://www.city-visitor.com/dundee/plumbers.html','r'); // i have added the url here
    while($cont = fread($site,1024657)){
        $total .= $cont;
    }
    fclose($site);
    $match_expression = '/<h1 class="Listing">(.*)<\/h1>/Us';
    preg_match($match_expression,$total,$matches);
    return $matches[1];
}

$type = get_type();

echo $type;
  1. function get_type(){
  2.     $site = fopen('http://www.city-visitor.com/dundee/plumbers.html','r'); // i have added the url here
  3.     while($cont = fread($site,1024657)){
  4.         $total .= $cont;
  5.     }
  6.     fclose($site);
  7.     $match_expression = '/<h1 class="Listing">(.*)<\/h1>/Us';
  8.     preg_match($match_expression,$total,$matches);
  9.     return $matches[1];
  10. }
  11. $type = get_type();
  12. echo $type;


Mais ce travail dosnt

Code: [ Select ]

$url = 'http://www.city-visitor.com/dundee/plumbers.html';

function get_type(){
    $site = fopen($url,'r'); // this time im calling the url from the $url from the variable two lines back
    while($cont = fread($site,1024657)){
        $total .= $cont;
    }
    fclose($site);
    $match_expression = '/<h1 class="Listing">(.*)<\/h1>/Us';
    preg_match($match_expression,$total,$matches);
    return $matches[1];
}


$type = get_type();

echo $type;
  1. $url = 'http://www.city-visitor.com/dundee/plumbers.html';
  2. function get_type(){
  3.     $site = fopen($url,'r'); // this time im calling the url from the $url from the variable two lines back
  4.     while($cont = fread($site,1024657)){
  5.         $total .= $cont;
  6.     }
  7.     fclose($site);
  8.     $match_expression = '/<h1 class="Listing">(.*)<\/h1>/Us';
  9.     preg_match($match_expression,$total,$matches);
  10.     return $matches[1];
  11. }
  12. $type = get_type();
  13. echo $type;




J'obtiens une erreur indiquant que ce n'est pas une ressource valide
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Mai 16th, 2009, 12:18 pm

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de l’utilisateur
  • Inscription: Mai 22, 2004
  • Messages: 3415
  • Loc: Richland, WA
  • Status: Offline

Message Mai 16th, 2009, 12:34 pm

Votre passant pas la variable $ url dans la fonction.

Code: [ Select ]
// Change this
function get_type(){
// To this
function get_type($url){
  1. // Change this
  2. function get_type(){
  3. // To this
  4. function get_type($url){
#define NULL (::rand() % 2)
  • dark_lord
  • Graduate
  • Graduate
  • Avatar de l’utilisateur
  • Inscription: Jan 14, 2009
  • Messages: 162
  • Loc: India-Kolkata
  • Status: Offline

Message Mai 16th, 2009, 11:23 pm

ou utilisez la variable globale

Code: [ Select ]
function get_type(){
    $site = fopen($url,'r'); // this time im calling the url
  1. function get_type(){
  2.     $site = fopen($url,'r'); // this time im calling the url


à
Code: [ Select ]
function get_type(){
global $url;
    $site = fopen($url,'r'); // this time im calling the url
  1. function get_type(){
  2. global $url;
  3.     $site = fopen($url,'r'); // this time im calling the url
Wrap Up your Big Url | Mariana World Community

Afficher de l'information

  • Total des messages de ce sujet: 3 messages
  • Utilisateurs parcourant ce forum: ScottG et 188 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC