1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

simple php script to save lines to columns

Discussion in 'PHP' started by ssimon171078, Sep 23, 2019.

  1. #1
    i started to write php script to show phones in columns:
    <?php
    I=0;
    $fh=fopen("phones.txt,"r");
    while(!feof($fh))
    {
      $content[]=fgets($fh);
    $i++;
    }
    fclose  ($fh);
    for($line=0;$line<=$i;$line++)
    {
      if (strpos($content[$line]"972")!=0
    {
    echo "\n"."<br>";
    echo  $content[$line];
    }
    Code (php):
    my text file phones :
    <span title="+1 (718) 207-0985, +1 (929) 402-6319, +39 346 386 6315, +44 7504 400424, +92 306 9386209, +972 50-223-8110, +972 50-235-2282, +972 50-240-8779, +972 50-281-1336, +972 50-334-3133, +972 50-371-7366, +972 50-383-4914, +972 50-465-6847, +972 50-475-5100, +972 50-507-1371, +972 50-507-6083, +972 50-546-0269, +972 50-564-7979, +972 50-568-5970, +972 50-582-1688, +972 50-627-3000, +972 50-647-1997, +972 50-678-7252, +972 50-679-0149, +972 50-692-2796, +972 50-696-0162, +972 50-699-9770, +972 50-749-9888, +972 50-752-3086, +972 50-777-7751, +972 50-835-8520, +972 50-858-9898, +972 50-865-7443, +972 50-944-2328, +972 50-944-5028, +972 50-990-5949, +972 51-232-4463, +972 51-505-1959, +972 52-203-9046, +972 52-249-6697, +972 52-260-0312, +972 52-263-0067, +972 52-268-2408, +972 52-300-6826, +972 52-301-0628, +972 52-362-9198, +972 52-377-5509, +972 52-382-7973, +972 52-404-6414, +972 52-448-1501, +972 52-455-9669, +972 52-465-1165, +972 52-465-6575, +972 52-478-2635, +972 52-510-0465, +972 52-567-0667, +972 52-585-6807, +972 52-603-5355, +972 52-604-4520, +972 52-612-1212, +972 52-625-5683, +972 52-636-9505, +972 52-637-8922, +972 52-701-5231, +972 52-743-7796, +972 52-745-0855, +972 52-749-8504, +972 52-763-8585, +972 52-764-5373, +972 52-766-0255, +972 52-767-0417, +972 52-782-5250, +972 52-822-2476, +972 52-873-9399, +972 52-883-2277, +972 52-966-2525, +972 52-997-6767, +972 53-234-5190, +972 53-240-5504, +972 53-250-2266, +972 53-319-3223, +972 53-352-0005, +972 53-426-8210, +972 53-428-5128, +972 53-494-9723, +972 53-521-5582, +972 53-531-4719, +972 53-700-5650, +972 53-716-5670, +972 53-721-1527, +972 53-721-1571, +972 53-722-5262, +972 53-727-5670, +972 53-821-5118, +972 53-929-1467, +972 53-933-6278, +972 53-959-7805, +972 54-251-5154, +972 54-261-0408, +972 54-265-9279, +972 54-290-2081, +972 54-312-4645, +972 54-334-3147, +972 54-434-5342, +972 54-440-4985, +972 54-444-0707, +972 54-452-3849, +972 54-452-5885, +972 54-490-9421, +972 54-522-4086, +972 54-540-8300, +972 54-565-3999, +972 54-592-8327, +972 54-609-3320, +972 54-641-0428, +972 54-672-7602, +972 54-684-6456, +972 54-690-0073, +972 54-712-1208, +972 54-712-1759, +972 54-728-5770, +972 54-758-9135, +972 54-806-6198, +972 54-815-6817, +972 54-836-5879, +972 54-847-8353, +972 54-854-2525, +972 54-981-2861, +972 54-983-2005, +972 54-987-3565, +972 55-255-4100, +972 55-255-4114, +972 55-550-1487, +972 55-661-8184, +972 55-664-6691, +972 55-664-7036, +972 55-704-3718, +972 55-711-7614, +972 55-724-8985, +972 55-727-6103, +972 55-727-8031, +972 55-883-0896, +972 55-926-4159, +972 55-949-5090, +972 55-971-8423, +972 55-971-8865, +972 55-987-8309, +972 55-991-5143, +972 58-396-1636, +972 58-415-6448, +972 58-420-3069, +972 58-426-9764, +972 58-444-0890, +972 58-476-1111, +972 58-494-8686, +972 58-551-4014, +972 58-562-0723, +972 58-629-3888, +972 58-680-4108, +972 58-713-5873, +972 58-754-8869, +972 58-780-4121, You" class="_315-i">+1 (718) 207-0985, +1 (929) 402-6319, +39 346 386 6315, +44 7504 400424, +92 306 9386209, +972 50-223-8110, +972 50-235-2282, +972 50-240-8779, +972 50-281-1336, +972 50-334-3133, +972 50-371-7366, +972 50-383-4914, +972 50-465-6847, +972 50-475-5100, +972 50-507-1371, +972 50-507-6083, +972 50-546-0269, +972 50-564-7979, +972 50-568-5970, +972 50-582-1688, +972 50-627-3000, +972 50-647-1997, +972 50-678-7252, +972 50-679-0149, +972 50-692-2796, +972 50-696-0162, +972 50-699-9770, +972 50-749-9888, +972 50-752-3086, +972 50-777-7751, +972 50-835-8520, +972 50-858-9898, +972 50-865-7443, +972 50-944-2328, +972 50-944-5028, +972 50-990-5949, +972 51-232-4463, +972 51-505-1959, +972 52-203-9046, +972 52-249-6697, +972 52-260-0312, +972 52-263-0067, +972 52-268-2408, +972 52-300-6826, +972 52-301-0628, +972 52-362-9198, +972 52-377-5509, +972 52-382-7973, +972 52-404-6414, +972 52-448-1501, +972 52-455-9669, +972 52-465-1165, +972 52-465-6575, +972 52-478-2635, +972 52-510-0465, +972 52-567-0667, +972 52-585-6807, +972 52-603-5355, +972 52-604-4520, +972 52-612-1212, +972 52-625-5683, +972 52-636-9505, +972 52-637-8922, +972 52-701-5231, +972 52-743-7796, +972 52-745-0855, +972 52-749-8504, +972 52-763-8585, +972 52-764-5373, +972 52-766-0255, +972 52-767-0417, +972 52-782-5250, +972 52-822-2476, +972 52-873-9399, +972 52-883-2277, +972 52-966-2525, +972 52-997-6767, +972 53-234-5190, +972 53-240-5504, +972 53-250-2266, +972 53-319-3223, +972 53-352-0005, +972 53-426-8210, +972 53-428-5128, +972 53-494-9723, +972 53-521-5582, +972 53-531-4719, +972 53-700-5650, +972 53-716-5670, +972 53-721-1527, +972 53-721-1571, +972 53-722-5262, +972 53-727-5670, +972 53-821-5118, +972 53-929-1467, +972 53-933-6278, +972 53-959-7805, +972 54-251-5154, +972 54-261-0408, +972 54-265-9279, +972 54-290-2081, +972 54-312-4645, +972 54-334-3147, +972 54-434-5342, +972 54-440-4985, +972 54-444-0707, +972 54-452-3849, +972 54-452-5885, +972 54-490-9421, +972 54-522-4086, +972 54-540-8300, +972 54-565-3999, +972 54-592-8327, +972 54-609-3320, +972 54-641-0428, +972 54-672-7602, +972 54-684-6456, +972 54-690-0073, +972 54-712-1208, +972 54-712-1759, +972 54-728-5770, +972 54-758-9135, +972 54-806-6198, +972 54-815-6817, +972 54-836-5879, +972 54-847-8353, +972 54-854-2525, +972 54-981-2861, +972 54-983-2005, +972 54-987-3565, +972 55-255-4100, +972 55-255-4114, +972 55-550-1487, +972 55-661-8184, +972 55-664-6691, +972 55-664-7036, +972 55-704-3718, +972 55-711-7614, +972 55-724-8985, +972 55-727-6103, +972 55-727-8031, +972 55-883-0896, +972 55-926-4159, +972 55-949-5090, +972 55-971-8423, +972 55-971-8865, +972 55-987-8309, +972 55-991-5143, +972 58-396-1636, +972 58-415-6448, +972 58-420-3069, +972 58-426-9764, +972 58-444-0890, +972 58-476-1111, +972 58-494-8686, +972 58-551-4014, +972 58-562-0723, +972 58-629-3888, +972 58-680-4108, +972 58-713-5873, +972 58-754-8869, +972 58-780-4121, You</span>
    Code (markup):
    i need to receive text file
    +972 58-713-5873
    +972 58-754-8869,....
    Code (markup):

     
    Last edited by a moderator: Sep 23, 2019
    ssimon171078, Sep 23, 2019 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    mistake 1:

    I=0

    did you mean $i?

    Mistake 2:
    
    while(!feof($fh)) {
    	$content[]=fgets($fh);
    	$i++;
    }
    fclose ($fh);
    for($line=0;$line<=$i;$line++)
    {
    
    Code (markup):
    Why are you creating a counter you don't need or use? Why are you wasting memory creating an "array for nothing" instead of just outputting as you read?

    Mistake #3:

    
    if (strpos($content[$line]"972")!=0
    Code (markup):
    This is just complete gibberish, this line shouldn't even RUN, you should get NO output becasue that "972" thrown in there is gibberish.

    Mistake #4:
    
    
    echo "\n"."<br>";
    echo $content[$line];
    
    Code (markup):
    Opening/closing double quotes for no reason, double quotes for no reason, multiple echo doing ONE echo's job.

    ... and why is your "data file" in a span as TITLE, and if that is in fact your file it doesn't HAVE multiple lines for fgets to split the file BY!

    As such your question makes less sense than the code you presented.
     
    deathshadow, Sep 23, 2019 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Your text file just needs grooming and exploding but the real question is what is your business case and where are you getting that data from? Are you scraping?
     
    sarahk, Sep 23, 2019 IP