I have a file which has many lines containing ##. I want to remove the part of string after ##.
Here is what I have tried
JavaScript
x
<?php
$file = fopen("testr.txt", "r");
$NewLineExplode = explode(PHP_EOL,$file);
$NewString = '';
foreach($NewLineExplode as $eachLine) {
$HashExlode = explode('##',$eachLine);
$NewString .= $HashExlode[0].'<br>';
}
echo $NewString;
?>
testr.txt look like this
JavaScript
citycredits.ru##.widget_banner
anvidelabs.org##.widget_banners
hcpeople.ru##.widget_board_ads
newsoboz.org##.widget_center > noindex
softolet.ru##.widget_custom_html
edurusnews.ru##.widget_execphp
poznamka.ru##.widget_hja_adsense
softolet.ru##.widget_media_image
yuzhny.info##.widget_media_image > img[width="360"][height="520"]
The output should be like this
JavaScript
citycredits.ru
anvidelabs.org
hcpeople.ru
newsoboz.org
softolet.ru
Advertisement
Answer
JavaScript
$string = fopen("testr.txt", "r");
$NewString = '';
// Output one line until end-of-file
while(!feof($string)) {
$HashExlode = explode('##',fgets($string));
$NewString .= $HashExlode[0].'<br>';
}
echo $NewString;
fclose($string);