{"id":556,"date":"2006-02-16T16:55:15","date_gmt":"2006-02-16T16:55:15","guid":{"rendered":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/"},"modified":"2006-02-16T16:55:15","modified_gmt":"2006-02-16T16:55:15","slug":"php-question","status":"publish","type":"post","link":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/","title":{"rendered":"PHP question"},"content":{"rendered":"<p>Apologies for the complete geekery of this post.<\/p>\n<p>I have some data in a file and I would like to manipulate it using PHP to produce an HTML output. Not being very familiar with file-handling, can anyone suggest how I get the data into a usable form?<\/p>\n<p>The input file contains (almost) fixed width data in the form:<\/p>\n<blockquote>\n<table border=0>\n<tr>\n<td width=80%>texttexttexttexttext                             <\/td>\n<td>#####<\/td>\n<\/tr>\n<tr>\n<td>textext                                         <\/td>\n<td>&nbsp;###<\/td>\n<\/tr>\n<tr>\n<td>texttextext                                    <\/td>\n<td>### <\/td>\n<\/tr>\n<\/table>\n<\/blockquote>\n<p>where texttexttext is a string and #### is a number.<\/p>\n<p>I&#8217;d like to import the file into a two-dimensional array, the first part containing the text (trimmed of spaces to the right), with the second containing the number (with any whitespace either side trimmed). The text field is 60 wide and the number field is 8 wide.<\/p>\n<p>Does anyone have any handy code to do this, please? I&#8217;ve had a Google and can&#8217;t find what I&#8217;m after. It&#8217;s not so much the trimming as getting the two bits of data into different parts of the array. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apologies for the complete geekery of this post. I have some data in a file and I would like to manipulate it using PHP to produce an HTML output. Not being very familiar with file-handling, can anyone suggest how I get the data into a usable form? The input file contains (almost) fixed width data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[224],"class_list":["post-556","post","type-post","status-publish","format-standard","hentry","category-geeklife","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP question - No geek is an island<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP question - No geek is an island\" \/>\n<meta property=\"og:description\" content=\"Apologies for the complete geekery of this post. I have some data in a file and I would like to manipulate it using PHP to produce an HTML output. Not being very familiar with file-handling, can anyone suggest how I get the data into a usable form? The input file contains (almost) fixed width data [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\" \/>\n<meta property=\"og:site_name\" content=\"No geek is an island\" \/>\n<meta property=\"article:published_time\" content=\"2006-02-16T16:55:15+00:00\" \/>\n<meta name=\"author\" content=\"Will\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Will\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\"},\"author\":{\"name\":\"Will\",\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300\"},\"headline\":\"PHP question\",\"datePublished\":\"2006-02-16T16:55:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\"},\"wordCount\":158,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300\"},\"keywords\":[\"php\"],\"articleSection\":[\"Geeklife\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\",\"url\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\",\"name\":\"PHP question - No geek is an island\",\"isPartOf\":{\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#website\"},\"datePublished\":\"2006-02-16T16:55:15+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.willhowells.org.uk\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP question\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#website\",\"url\":\"https:\/\/www.willhowells.org.uk\/blog\/\",\"name\":\"No geek is an island\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.willhowells.org.uk\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300\",\"name\":\"Will\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/edd7c0105cc6a39125db7653749feae1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/edd7c0105cc6a39125db7653749feae1?s=96&d=mm&r=g\",\"caption\":\"Will\"},\"logo\":{\"@id\":\"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.willhowells.org.uk\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP question - No geek is an island","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/","og_locale":"en_US","og_type":"article","og_title":"PHP question - No geek is an island","og_description":"Apologies for the complete geekery of this post. I have some data in a file and I would like to manipulate it using PHP to produce an HTML output. Not being very familiar with file-handling, can anyone suggest how I get the data into a usable form? The input file contains (almost) fixed width data [&hellip;]","og_url":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/","og_site_name":"No geek is an island","article_published_time":"2006-02-16T16:55:15+00:00","author":"Will","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Will","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#article","isPartOf":{"@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/"},"author":{"name":"Will","@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300"},"headline":"PHP question","datePublished":"2006-02-16T16:55:15+00:00","mainEntityOfPage":{"@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/"},"wordCount":158,"commentCount":7,"publisher":{"@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300"},"keywords":["php"],"articleSection":["Geeklife"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/","url":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/","name":"PHP question - No geek is an island","isPartOf":{"@id":"https:\/\/www.willhowells.org.uk\/blog\/#website"},"datePublished":"2006-02-16T16:55:15+00:00","breadcrumb":{"@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.willhowells.org.uk\/blog\/2006\/02\/16\/php-question\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.willhowells.org.uk\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP question"}]},{"@type":"WebSite","@id":"https:\/\/www.willhowells.org.uk\/blog\/#website","url":"https:\/\/www.willhowells.org.uk\/blog\/","name":"No geek is an island","description":"","publisher":{"@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.willhowells.org.uk\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/143a6b60a322d001fdc07f2007384300","name":"Will","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/edd7c0105cc6a39125db7653749feae1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/edd7c0105cc6a39125db7653749feae1?s=96&d=mm&r=g","caption":"Will"},"logo":{"@id":"https:\/\/www.willhowells.org.uk\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.willhowells.org.uk\/blog"]}]}},"_links":{"self":[{"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/posts\/556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/comments?post=556"}],"version-history":[{"count":0,"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/posts\/556\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/media?parent=556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/categories?post=556"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.willhowells.org.uk\/blog\/wp-json\/wp\/v2\/tags?post=556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}