No announcement yet.

Simple PHP script to break lines

  • Time
  • Show
Clear All
new posts

  • Simple PHP script to break lines

    Hi all,

    I must compare two .js files that have the format below:

    var item = [
      ['pagefile1.html', 'Page Name 1', 'keyword1, keyword2, keyword3, ...'],
      ['pagefile2.html', 'Page Name 2', 'keyword4, keyword5, keyword6, ...'],
      // etc.
    However, when BC3 spots a difference, it always shows the whole line. That's not very useful for long lines, because I have to scroll horizontally to see which are the different words (incidentally, anyone knows a way to show only the different words / characters? I'd love to see this feature). So I created a very simple PHP script that breaks all lines, like this:

    //  Very simple PHP script to convert commas to line breaks
    //  Usage in BC3: C:\php5\bin\php.exe C:\php5\scripts\search.php %s %t
    $source = file($argv[1]);
    $target = array();
    foreach($source as $line) {
    	$line = str_replace(",", PHP_EOL, $line);
    	// ... Additional processing goes here
    	$target[] = $line;
    file_put_contents($argv[2], $target);
    In BC, I've created a new text format, then added the command line above to the 'Loading' field that exists in the Conversion tab. This script breaks all source lines into separate words in the target file, one per line. This way I can see only the relevant differences: that's exactly what I wanted. Adding extra processing is easy, just include more str_replace() or preg_replace() commands.

    Hope this is useful to someone!

  • #2
    Thanks for the contribution! I'm sure some of our customers will find this useful.

    Here is a link to our KB article on how to create a custom File Format:
    Last edited by Aaron; 22-Jan-2010, 10:19 AM. Reason: adding link
    Aaron P Scooter Software