DeepakJ Posted August 7, 2007 Share Posted August 7, 2007 Ok I need to explode the following file around | but the problem is that there is a huge space between the first line and the second. Manually changing the file is not an option considering there are about 2000 of these files. I was wondering if someone could tell me how to get rid of the large space. This is how my file looks like: Service Pack 2 for VisualMill 5 has been released! 0|Please go to Downloads->Service Packs and download the Service Pack 2 for VisualMill. <br><br>You can also get the complete product with Service Pack included from the Support->Download 5.0 link.<br><br>The bugs fixed in this Service Pack are as follows:<br><br>1. Added rotate by 3 points to command to Edit menu <br>2. Added Angle command to Measure toolbar <br>3. Changed precision of measure output <br>4. Saving/Restoring maximum simulation settings from browser <br>5. Allowing animation if stock model is not loaded <br>6. V-Cutting bug fixed <br>7. Fixed Climb/Conventional bug in pocketing, horizontal optimized finishing <br>8. Angle is input as radians rather than degrees for command line version of rotate <br>9. Thread tool simulation error fixed <br>10. Profile number of cuts not transferred from V4 to V5 fixed <br>11. Extract surface edges now extracts the closest edge to the pick point rather than all of the edges <br>12. A Rhino surface importing problem fixed <br>13. Rotated 21/2 Axis was not working correctly <br>14. Introducing 4Axis add-on for VisualMill Basic <br>15. Resource changes for multi language support <br>16. Advanced cut levels fixes for multi-language support|1073425551|MecSoft Support|199.174.76.62 Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/ Share on other sites More sharing options...
Daniel0 Posted August 7, 2007 Share Posted August 7, 2007 What huge space? Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317623 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Between the ! and the 0 Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317626 Share on other sites More sharing options...
effigy Posted August 7, 2007 Share Posted August 7, 2007 The new line? Are the files always in this format? I don't quite grasp what you're trying to do... Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317627 Share on other sites More sharing options...
Daniel0 Posted August 7, 2007 Share Posted August 7, 2007 It's just a line break. I don't see why you can't use explode() on that string. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317628 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 When i explode that file it only comes up with the first line. If I get rid of that line then explode works fine. I can attach the file if it makes more sense. This program is basically a forum converter and posts from the old forum are in that format. I need to change the format to queries which can be put into mysql. I basically have a PHP script echo the code using fopen and then echoing exploded parts of the script into a query. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317633 Share on other sites More sharing options...
effigy Posted August 7, 2007 Share Posted August 7, 2007 Open the file, skip the first line, explode the second? Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317644 Share on other sites More sharing options...
pyrodude Posted August 7, 2007 Share Posted August 7, 2007 So explode the file based on the \n character, and then explode array1[1] based on the | character. You'll have the thread topic in array1[0] and the thread body in array2[] Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317647 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Well I don't know if that will work. I first exploded the whole file and the first line came out only when I did a foreach echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317651 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Try: <?php $lines = file('file.txt'); $k = 0; $new_lines = array(); for($i = 0; $i < count($lines)/2; $i++) { $new_lines[] = trim($lines[$k]) . '|' . $lines[$k+1]; $k = $i+2; } foreach($new_lines as $line) { list($header, $id, $content, $timestamp, $author, $ip) = explode('|', $line); $date = date('D jS M Y', $timestamp); $id++; $content = nl2br($content); echo <<<EOF <h1>$header</h1> <p>#$id - Posted by: $author ($ip) at $date</p> <p>$content</p> <hr /> EOF; } ?> I'm asumming your file goes in this format: Heading [post-id]|[content for post]|[timestamp]|[Author]|[iP Address of Author] Heading [post-id]|[content for post]|[timestamp]|[Author]|[iP Address of Author] Heading [post-id]|[content for post]|[timestamp]|[Author]|[iP Address of Author] Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317652 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Replace post id with body. The new forum bases post id with the timestamp. Or does PHPBB forums do it differently? Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317655 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 nvm your format is correct. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317657 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Im just saying post id would be irrelavent (Or so I think) in the new forums considering POSTID has to be unique in there. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317660 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Huh! Who you replying to? Are you replying to me? If you are im not sure what you mean by your posts about phpbb and postid. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317663 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Yeah Im replying to you. Im saying that the post order in threads I beleive is based on timestamp rather than the id in phpbb forums, hence there useless ness. Ive been trying another approach but get this error. Im not too exp with fopen so some troubleshooting help would be appreciaited. <b>Fatal error</b>: Cannot break/continue 1 level in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Forums\index1.php</b> on line <b>37</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317668 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Try: <?php $lines = file('file.txt'); $k = 0; $new_lines = array(); for($i = 0; $i < count($lines)/2; $i++) { $new_line = trim($lines[$k+1]); $col = explode('|', $new_line); $id = $col[0]; $timestamp = $col[2]; $new_line = str_replace(array($id . '|', $timestamp . '|'), '', $new_line); $new_lines[$timestamp] = trim($lines[$k]) . '|' . $new_line; $k += 2; } ksort($new_lines); foreach($new_lines as $k => $line) { list($header, $content, $author, $ip) = explode('|', trim($line)); $date = date('D jS M Y', $k); $id++; $content = str_replace('<br>', "<br />\n ", $content); echo "<h1>$header</h1> <p>Posted by: $author ($ip) at $date</p> <p> $content </p>\n <hr />\n"; } ?> I have removed the post id and the posts should display in ascending order (earliest (top) to recent (bottom)) Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317705 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Im getting these errors. Thanks alot for your time nad effort Notice: Undefined offset: 1 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Forums\file.php on line 10 Notice: Undefined offset: 2 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Forums\file.php on line 15 Warning: date() expects parameter 2 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Forums\file.php on line 30 Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317713 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Have you modified the file.txt's format. Make sure its in this format: [post title] [post id]|[content for post]|[timstamp]|[author]|[ip address] Looks like you have changed that file and the code has broken due to the changes you have made to the file The result of running the script will be this Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317720 Share on other sites More sharing options...
DeepakJ Posted August 7, 2007 Author Share Posted August 7, 2007 Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for '-7.0/DST' instead in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Forums\file.php on line 30 Now I am getting this error Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317723 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Lower PHP's error_reporting level to E_ALL rather than E_STRICT. Note: when you make any changes to the php.ini your must restart Apache for the changes to take affect. Quote Link to comment https://forums.phpfreaks.com/topic/63744-solved-modifying-large-strings-or-files/#findComment-317741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.