filmov
tv
Excel VBA tutorials to enhance WordPress pages - #4 - Searching data files #2

Показать описание
Coding for Part IV below
Part IV
Search box code Part II
Copy these notes to NotePad and save.
NOTE: this follows on from Video III; view that first and copy notes from its Youtube Description.
1. Almost same PHP code as previous video; see new lines added.
[insert_php]
$search_string=htmlspecialchars($_POST["search"]) ;
$count=0 ;
if ($search_string=="") {$search_string="null" ;}
// NOTE: Youtube 'Description' does not allow HTML characters so change ++ into the opening left pointing bracket and +++ into the closing right pointing bracket (delete this note)
print "++br+++ Records found which include search term: '" . $search_string . "'++p+++" ;
$open_file = fopen( $filepath, "r") ;
while ($row = fgets($open_file)) {
$string_position=stripos($row,$search_string) ;
if($string_position!==false) {
$array_parts = explode(',', $row ) ;
$university=$array_parts[0] ;
// ======================================================================New lines
$wikifile =fopen( $filepath2, "r") ;
$textoutput=fgets($wikifile) ;
if (stripos($textoutput,$search_string)!==false){ $textstart=stripos($textoutput,$search_string);} else {$textstart=0 ;}
$extract=substr($textoutput,$textstart,250) ;
fclose($wikifile) ;
// ======================================================================End new lines
$count=$count+1 ;
// NOTE: Youtube 'Description' does not allow HTML characters so change ++ into the opening left pointing bracket and +++ into the closing right pointing bracket (delete this note)
print $count . ": ++a href='" . $strURL . "/php-text-files/?uni=" . $university . "'+++" . $university . "++/a+++.." . $extract . "++p+++" ;
} // end of if conditional
} // end of while loop
if ($count==0){ echo "No files found for search item '" . $search_string . "'" ; }
fclose($open_file) ;
[/insert_php]
----------------------------------------- end
View Page;
'Null' to start until search box used and search term found - try 'sheffield', 'leeds', 'russell group', 'Yorkshire', 'medical' etc.
End Part IV
Part IV
Search box code Part II
Copy these notes to NotePad and save.
NOTE: this follows on from Video III; view that first and copy notes from its Youtube Description.
1. Almost same PHP code as previous video; see new lines added.
[insert_php]
$search_string=htmlspecialchars($_POST["search"]) ;
$count=0 ;
if ($search_string=="") {$search_string="null" ;}
// NOTE: Youtube 'Description' does not allow HTML characters so change ++ into the opening left pointing bracket and +++ into the closing right pointing bracket (delete this note)
print "++br+++ Records found which include search term: '" . $search_string . "'++p+++" ;
$open_file = fopen( $filepath, "r") ;
while ($row = fgets($open_file)) {
$string_position=stripos($row,$search_string) ;
if($string_position!==false) {
$array_parts = explode(',', $row ) ;
$university=$array_parts[0] ;
// ======================================================================New lines
$wikifile =fopen( $filepath2, "r") ;
$textoutput=fgets($wikifile) ;
if (stripos($textoutput,$search_string)!==false){ $textstart=stripos($textoutput,$search_string);} else {$textstart=0 ;}
$extract=substr($textoutput,$textstart,250) ;
fclose($wikifile) ;
// ======================================================================End new lines
$count=$count+1 ;
// NOTE: Youtube 'Description' does not allow HTML characters so change ++ into the opening left pointing bracket and +++ into the closing right pointing bracket (delete this note)
print $count . ": ++a href='" . $strURL . "/php-text-files/?uni=" . $university . "'+++" . $university . "++/a+++.." . $extract . "++p+++" ;
} // end of if conditional
} // end of while loop
if ($count==0){ echo "No files found for search item '" . $search_string . "'" ; }
fclose($open_file) ;
[/insert_php]
----------------------------------------- end
View Page;
'Null' to start until search box used and search term found - try 'sheffield', 'leeds', 'russell group', 'Yorkshire', 'medical' etc.
End Part IV