PHP to search within txt file and echo the whole line

And a PHP example, multiple matching lines will be displayed: <?php $file=”somefile.txt”; $searchfor=”name”; // the following line prevents the browser from parsing this as HTML. header(‘Content-Type: text/plain’); // get the file contents, assuming the file to be readable (and exist) $contents = file_get_contents($file); // escape special characters in the query $pattern = preg_quote($searchfor, “https://stackoverflow.com/”); // … Read more

Reference: Comparing PHP’s print and echo

Why two constructs? The truth about print and echo is that while they appear to users as two distinct constructs, they are both really shades of echo if you get down to basics, i.e. look at the internal source code. That source code involves the parser as well as opcode handlers. Consider a simple action … Read more

php – insert a variable in an echo string

Single quotes will not parse PHP variables inside of them. Either use double quotes or use a dot to extend the echo. $variableName=”Ralph”; echo ‘Hello ‘.$variableName.’!’; OR echo “Hello $variableName!”; And in your case: $i = 1; echo ‘<p class=”paragraph’.$i.'”></p>’; ++i; OR $i = 1; echo “<p class=”paragraph$i”></p>”; ++i;

PHP echo vs PHP short echo tags

<? and <?= are called short open tags, and are not always enabled (see the short_open_tag directive) with PHP 5.3 or below (but since PHP 5.4.0, <?= is always available). Actually, in the php.ini-production file provided with PHP 5.3.0, they are disabled by default: $ grep ‘short_open’ php.ini-production ; short_open_tag short_open_tag = Off So, using … Read more

Why can’t I specify an environment variable and echo it in the same command line?

What you see is the expected behaviour. The trouble is that the parent shell evaluates $SOMEVAR on the command line before it invokes the command with the modified environment. You need to get the evaluation of $SOMEVAR deferred until after the environment is set. Your immediate options include: SOMEVAR=BBB eval echo zzz ‘$SOMEVAR’ zzz. SOMEVAR=BBB … Read more

How can I repeat a character in Bash?

You can use: printf ‘=%.0s’ {1..100} How this works: Bash expands {1..100} so the command becomes: printf ‘=%.0s’ 1 2 3 4 … 100 I’ve set printf’s format to =%.0s which means that it will always print a single = no matter what argument it is given. Therefore it prints 100 =s.