Jump to content

Delete characters in file


jcgomar

Recommended Posts

Hi to all,

I have a file I need to get information from but it's just a lot to remove to have the information in order, but the information I need is inside of a pair of %% and ##, other than that I want to remove pretty much everithing else.

I wonder if there's any way to have php open this file, analize it and remove everithing that is not inside those %% and ##

Example:

var listings = new Array("b01_DIREC SAT TV%%800-200-0017##68p310p874"

I just want:

8002000017

I hope somebody can help me with this!,

Regards,
Link to comment
https://forums.phpfreaks.com/topic/34351-delete-characters-in-file/
Share on other sites

Thanks for the fast reply, here's my problem:

I have .htm files I need to extract the phone numbers from, if you can notice they come between the %% and ##.

I need to have the output to be a list of those numbers in this format:

8001234567;
8002345678;
8003456789;
8009876543;
8008765432;

Here's the file:

<HTML><HEAD><SCRIPT LANGUAGE="JavaScript1.2">
var listings = new Array("b01_DIREC SAT TV%%800-200-0017##68p310p874","b01_DIREC TV%%800-200-0014##68p500p582","b01_DIRECT A SATELLITE TV%%800-200-0017##68p500p631","b01_DIRECT A TV SATELLITE SALES NO CHARGE TO CALLING PARTY%%800-200-0035##68p500p653","b01_DIRECT SAT TV%%800-200-0017##68p500p914","b01_DIRECT T V%%800-200-0017##69p109p468","b01_DIRECTV%%800-200-0017##69p299p530","b01_DIRECTV%%800-200-0004##69p299p374","b01_DIRECTV SALT LAKE CITY%%800-200-0004##69p489p319","b01_DIS NETWORK%%800-200-0033##69p489p518","b01_DISH A NETWORK%%800-200-0033##70p119p935","b01_DISH NETAWORK%%800-200-0033##70p310p324","b01_DISH NETWERK%%800-200-0033##70p310p346","b01_DISH NETWORK%%800-200-0094##70p310p701","b01_DISH NETWORK%%800-200-0092##70p310p690","b01_DISH NETWORK%%800-200-0033##70p310p679","b01_EARTHLINK%%800-200-0215##74p310p286","b01_EARTHLINK%%800-200-0080##74p119p951","b01_DISH NETWORK%%800-200-1285##70p310p712","b01_SUMMIT ACCOMMODATORS%%435-200-1031##208p310p570","b01_BIG BOY'S TOYS%%888-200-2697##27p489p292","b01_DISH NETWARK%%800-200-2043##70p310p335","b01_DISH NETWORK%%800-200-2043##70p310p368","b01_DISH NETWORK%%800-200-3404##70p310p722","b01_ALIANCE USA-IA%%800-200-5997##9p109p519","b01_HERBALIFE DISTRIBUTOR%%800-200-9876##99p299p915","b01_DIREC TV ACTIVATIONS AND SALES%%800-201-0848##68p500p593","b01_DIRECT A TV ACTIVATIONS AND SALES%%800-201-0605##68p500p642","b01_DISH DIRECT%%800-201-0965##70p119p958","b01_DISH NETWORK%%800-201-0301##70p310p739","b01_DISH NETWORK%%800-201-0194##70p310p733","b01_DISH NETWORK%%800-201-1960##70p310p760","b01_DISH NETWORK%%800-201-1206##70p310p749","b01_DIRECT SATELLITE TV%%800-201-2940##69p109p286","b01_SPRINT/NEXTEL%%800-201-2090##204p310p479","b01_NEXTEL CELLULAR SALES%%800-201-3934##152p500p855","b01_T-MOBILE CELLULAR SALES%%800-201-3979##211p109p822","b01_CINGULAR WIRELESS SALES%%800-201-4147##51p299p366","b01_SPECIALTY APPAREL%%201-6910##203p109p742","b01_PEOPLE PC AUTHORIZED AGENT%%800-201-8858##161p489p942");
</script>
<SCRIPT LANGUAGE="JavaScript" src="../../nortclik.js"></script>
<SCRIPT LANGUAGE="JavaScript1.2" src="search.js"></script></HEAD><BODY></BODY></HTML>

As this one, I have 400 more that I need to filter.

Thanks a lot for the quick help.
[quote]I copied all the html code you have posted and assigned it to variable ($DATA)

$DATA = preg_replace('/\-/mi', '', $DATA);
preg_match_all('/\%\%(.*?)\#\#/mi', $DATA,$out );
$d = $out[1];
print_r($d);
[/quote]
This is what it returned:

Array ( [0] => 8002000017 [1] => 8002000014 [2] => 8002000017 [3] => 8002000035 [4] => 8002000017 [5] => 8002000017 [6] => 8002000017 [7] => 8002000004 [8] => 8002000004 [9] => 8002000033 [10] => 8002000033 [11] => 8002000033 [12] => 8002000033 [13] => 8002000094 [14] => 8002000092 [15] => 8002000033 [16] => 8002000215 [17] => 8002000080 [18] => 8002001285 [19] => 4352001031 [20] => 8882002697 [21] => 8002002043 [22] => 8002002043 [23] => 8002003404 [24] => 8002005997 [25] => 8002009876 [26] => 8002010848 [27] => 8002010605 [28] => 8002010965 [29] => 8002010301 [30] => 8002010194 [31] => 8002011960 [32] => 8002011206 [33] => 8002012940 [34] => 8002012090 [35] => 8002013934 [36] => 8002013979 [37] => 8002014147 [38] => 2016910 [39] => 8002018858 )

How can I do to get the array parameters removed and just have the numbers without the "=>[n]" and at the end of every number to have a "\n" or something to have a number per line?

Archived

This topic is now archived and is closed to further replies.

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