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
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;

?>

 

:)

Link to comment
Share on other sites

  • 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 :) :) :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.