Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Following a <a href="http://chat.stackoverflow.com/transcript/10934/16-19">discussion in chat</a>, one solution using PHP as a command line script would look like this - </p> <pre><code>#! /usr/bin/php &lt;?php $options = getopt("f:r:"); $inputFile = $options['f']; $replacement = $options['r']; // read entire contents of input file $inputFileContents = file_get_contents($inputFile); // setup the regex and execute the search $pattern = '/.*link.*href=["|\']?(.*[\\\|\/]?.*)\.css["|\']?.*/'; preg_match_all($pattern, $inputFileContents, $matches); // remove last occurance of regex // these are the lines we'll want to hang onto $matchedLines = $matches[0]; array_pop($matchedLines); // isolate the last css file name $matchedFileName = array_pop($matches[1]); // first substitution replaces all lines with &lt;link&gt; with // an empty string (deletes them) $inputFileContents = str_replace($matchedLines,'',$inputFileContents); // second substitution replaces the matched file name // with the desired string $inputFileContents = str_replace($matchedFileName,$replacement,$inputFileContents); //*/ // save to new file for debugging $outputFileName = "output.html"; $outputFile = fopen($outputFileName,'w+'); fwrite($outputFile,$inputFileContents); fclose($outputFile); /*/ // save changes to original file $origFile = fopen($inputFile,'w+'); fwrite($origFile,$inputFileContents); fclose($origFile); //*/ exit(); ?&gt; </code></pre> <p>You would execute this script from the command line like so - </p> <pre><code>$ php thisScript.php -f "input.html" -r "hello-world" </code></pre> <ul> <li><code>-f</code> is the input file that we are parsing. </li> <li><code>-r</code> is the replacement string for the css file name (in this example "hello-world").</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload