Forum Moderators: coopster
tip1 = 'Nate Abeare<br>(810) 625-2374';
This is what I have, exciting huh!
<?php $url = "http://example.com/prospectlist.html";
$filepointer = fopen($url,"r");
if($filepointer){
while(!feof($filepointer)){
$buffer = fgets($filepointer,4096);
$file .= $buffer;
}
fclose($filepointer);
} else {
die("Could not open file");
}
?>
<?php
$regexname = "/[tip1 = ']/";
preg_match_all($regexname,$file,$match);
$result = $match[1];
echo $result ;
?>
[edited by: eelixduppy at 1:37 pm (utc) on Aug. 28, 2007]
[edit reason] use example.com, please [/edit]
Is tip1 part of it, you meant it to be a variable.
I will take the easier case :). If $tip1 is a variable, you can just explode it.
$tip1 = 'Nate Abeare<br>(810) 625-2374';
$new = explode("<br>",$tip1);
This gives you:
Array
(
[0] => Nate Abeare
[1] => (810) 625-2374
)
Habtom
[1] => Array
(
[0] => Nate Abeare
)
[2] => Array
(
[0] => (810) 625-2374
)
)
so the name is in $match[1][0] and the telephone number is in $match[2][0].
If there's more than one 'tip' line in each file, the names will be elements of $match[1] ($match[1][0], $match[1][1]...) and the telephone numbers of $match[2].
If there's only one tip per file, use preg_match instead of preg_match_all - that will simplify the arrays by a level - the name will be in $match[1] and the telephone number in $match[2].
Array ( [0] => GemREI .com [1] => Nate Abeare [2] => Joe Accardi [3] => ruhel ahmed [4] => abraham akhavan [5] => O Allende [6] => Ken Anderson [7] => dave ardolino [8] => Garrie Arnett [9] => M.Fatih Arslan [10] => Sharon Barbour [11] => osman barrie [12] => Michael Baum [13] => Bhaskar Bhatt [14] => James Black )
<?php $url = "http://example.com/prospectlist.html";
$filepointer = fopen($url,"r");
if($filepointer){
while(!feof($filepointer)){
$buffer = fgets($filepointer,4096);
$file .= $buffer;
}
fclose($filepointer);
} else {
die("Could not open file");
}
?>
<?php
$regexname = "/tip1 = '([^<]*)<br>([^']*)/";
preg_match_all($regexname,$file,$match);
$result = $match[1];
print_r($result) ;
?>
how do I get this to output as say list.txt being tab delaminated so it goes name{tab}number?
btw you guys are awesome, i've gotten more help in 5 mins then 4 days on simular forums.
[edited by: eelixduppy at 1:38 pm (utc) on Aug. 28, 2007]
[edit reason] example.com [/edit]
Open a file for writing, then use fputs:
for($i = 0; $i < $count; $i++)
fwrite($filepointer,"{$match[1][$i]}\t{$match[2][$i]}\n");
Or you could use fprintf [us2.php.net].
i have :
$newfile = 'list.txt'
fopen ($newfile,"w");
$count = preg_match_all($regexname,$file,$match);for($i = 0; $i < $count; $i++)
fwrite($filepointer,"{$match[1][$i]}\t{$match[2][$i]}\n");
$regexname = "/tip1 = '([^<]*)<br>([^']*)/";
Warning: preg_match_all() expects parameter 2 to be string, resource given in C:\xampp\htdocs\test.php on line 31
Warning: fclose(): 3 is not a valid stream resource in C:\xampp\htdocs\test.php on line 34
lines 28-34
$regexname = "/tip1 = '([^<]*)<br>([^']*)/";
$newfile = 'list.txt' ;
$file = fopen ($newfile,"w");
$count = preg_match_all($regexname,$file,$match);
for($i = 0; $i < $count; $i++)
fwrite($filepointer,"{$match[1][$i]}\t{$match[2][$i]}\n");
fclose($filepointer);
<?php $url = "http://example.com/prospectlist.html";
$filepointer = fopen($url,"r");
if($filepointer){
while(!feof($filepointer)){
$buffer = fgets($filepointer,4096);
$file .= $buffer;
}
fclose($filepointer);
} else {
die("Could not open file");
}
?>
<?php
$regexname = "/tip1 = '([^<]*)<br>([^']*)/";
$newfile = 'list.txt' ;
$file = fopen ($newfile,"w");
$count = preg_match_all($regexname,$file,$match);
for($i = 0; $i < $count; $i++)
fwrite($filepointer,"{$match[1][$i]}\t{$match[2][$i]}\n");
fclose($filepointer);
//preg_match_all($regexname,$file,$match);
// $result = $match[1][0],;
//print_r($result) ;
?>
[edited by: eelixduppy at 1:36 pm (utc) on Aug. 28, 2007]
[edit reason] use example.com, please [/edit]
<?php
$url = "http://example.com/prospectlist.html";
$filepointer = fopen($url,"r");
if($filepointer){
while(!feof($filepointer)){
$buffer = fgets($filepointer,4096);
$file .= $buffer;
}
fclose($filepointer);
} else {
die("Could not open file");
}
?>
<?php
$regexname = "/tip1 = '([^<]*)<br>([^']*)/";
$count = preg_match_all($regexname,$file,$match);
$newfile = 'list.txt'; [1][edited by: eelixduppy at 1:39 pm (utc) on Aug. 28, 2007]
$filepointer= fopen ($newfile,"w");
for($i = 0; $i < $count; $i++)
fwrite($filepointer,"{$match[$i]}\t{$match[2][$i]}\n");
fclose($filepointer);
?>
The way you have it written, I don't think so, it's just going to get it in 4K chunks. Offhand I'm not sure what size limits you might have. If you get errors of that sort, you could have both files open at the same time and look at the input a line at a time (look at fgets [us2.php.net]).