');
$copyright = substr( $whitney_string , $pos );
$pos = strpos ($copyright, '
');
$copyright = substr($copyright , 0, $pos+6);
$copyright_new = '
All content © 2008 Whitney Museum of American Art
Additional programming by OT!OM! Labs
This open source project uses PHP for content scraping and the Google Language API for language detection and translation: Show Code.
';
$whitney_string = str_replace($copyright,$copyright_new,$whitney_string);
//THE HOUSEKEEPING IS DONE. NOW WE WANT TO REBUILD THE MAIN ARTICLE
//SO THAT IT CAN BE MANIPULATED BY THE GOOGLE LANGUAGE API
//get the original main text
$pos = strpos( $whitney_string , 'Additional programming by OT!OM! Labs
This open source project uses PHP for content scraping and the Google Language API for language detection and translation: Show Code.
');
//echo "";
$main_text = substr( $whitney_string , $pos );
$pos = strpos( $main_text , '
');
//echo "";
$main_text = substr( $main_text , 0, $pos );
//some pages are missing the closing paragraph tag for the "Born..." para...
//$main_text = preg_replace('()(.)()','
',$main_text); $main_text = str_replace('\s
','
',$main_text); //$pos = strpos( $main_text , '
'); $pos = strpos( $main_text , ''); //echo ""; $main_text = substr( $main_text , $pos+4 ); //now, create the new main text //start by stripping html tags (paragraphs, mostly) $main_text_new = strip_tags($main_text); $main_text_new = trim($main_text_new); //replace html special characters--these cause problems for the translation //$search = array("’","—","“","”"); $search = array("’","—","“","”","≈","Ω",); $replace = array ("'", " - ","\"","\"","ff","ff"); //the cleaned up string $main_text_new =str_replace($search,$replace,$main_text_new); //now build new sentences $sentences= preg_split('/\.\s/', $main_text_new, -1 , PREG_SPLIT_NO_EMPTY); $num_sentences = count ($sentences); $main_text_new_sentences = "\n" ; for ($i=0;$i<$num_sentences;$i++){ $sentences[$i] = trim($sentences[$i]); $main_text_new_sentences .= "\n".$sentences[$i].". "; if ($i%3==2){$main_text_new_sentences .= "
\n";} } $main_text_new_sentences .= "
\n"; $whitney_string = str_replace($main_text,$main_text_new_sentences,$whitney_string); //trim the string from the tag on, because we're going to add our javascript at the bottom of the page $pos = strpos( $whitney_string , '