Jump to content

rading wep pages with php


jk11uk

Recommended Posts

hi guys

 

 

i'd like to make a script that goes through a site (has dynamic URLs) and reads a certain line of text from each page and extracts the second number in from it.

 

my question is: how do you get a php script to access a URL and extract the source code of the page and store it into a varialbe?

 

secondly: how would you then extract a certain sentence from the page if you know what the starting few words will always be and the ending few words? so if i know it will be 'word one word two UNKNOWN WORDS end word'.

 

 

 

thanks so much for any assistance some genious can offer :) !

Link to comment
https://forums.phpfreaks.com/topic/82534-rading-wep-pages-with-php/
Share on other sites

<?php

function textbetweenarray($s1,$s2,$s){
$myarray=array();
$s1=strtolower($s1);
$s2=strtolower($s2);
$L1=strlen($s1);
$L2=strlen($s2);
$scheck=strtolower($s);

do{
$pos1 = strpos($scheck,$s1);
if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
$myarray[]=substr($s,$pos1+$L1,$pos2);
$s=substr($s,$pos1+$L1+$pos2+$L2);
$scheck=strtolower($s);
}
}
} while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$code = file_get_contents("http://www.site.com");

list($words) = textbetweenarray("word one word two ", " end word", $code);

echo $words;

?>

 

:)

  • 1 month later...

thanks a lot, it works ish. The only problem is that when the value it returns has a comma or fullstop in it, it doesn't return anything

 

i am using this to enter the found string into a database and the database gets updated correctly with the data for any string without this punctuation. any ideas on how to fix it?

 

eg. this will work - string found: dfgdfgsdf

but this wont: 123,44

nor will this: dsfsd,32

 

 

thanks again in advance :) :) :)

modifyers i and u? Sorry, i have no experience with regex or this type of coding. Is there any chance you could help me using the code above? This code half works, so hopefully there is a small change that can be made to make it take values even if there is a comma or fullstop?

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.