snipt

Ctrl+h for KB shortcuts

PHP

icdsoft create rails project from php script

1
2
3
4
<?php
putenv("HOME=/home/$user");
system("rails project_name 2>&1");
?>
https://snipt.net/embed/4fca390133c45f593726a0d876309ef8/
/raw/4fca390133c45f593726a0d876309ef8/
4fca390133c45f593726a0d876309ef8
php
PHP
4
2019-06-04T11:46:52
True
False
False
/api/public/snipt/4979/
icdsoft-create-rails-project-from-php-script
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">putenv</span><span class="p">(</span><span class="s2">&quot;HOME=/home/</span><span class="si">$user</span><span class="s2">&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">system</span><span class="p">(</span><span class="s2">&quot;rails project_name 2&gt;&amp;1&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
php, rails

PHP

php if shorthand

<? echo "var is ".($var < 0 ? "negative" : "positive");
https://snipt.net/embed/0a3a593722480fb66f2dcf2750d8ba85/
/raw/0a3a593722480fb66f2dcf2750d8ba85/
0a3a593722480fb66f2dcf2750d8ba85
php
PHP
1
2019-06-16T20:23:27
True
False
False
/api/public/snipt/4621/
php-if-shorthand
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> <span class="k">echo</span> <span class="s2">&quot;var is &quot;</span><span class="o">.</span><span class="p">(</span><span class="nv">$var</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="o">?</span> <span class="s2">&quot;negative&quot;</span> <span class="o">:</span> <span class="s2">&quot;positive&quot;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
php

Text only

set php to run with php5 in htaccess

AddType x-mapp-php5 .php
https://snipt.net/embed/807f2d70419959efdb87cf004610db6e/
/raw/807f2d70419959efdb87cf004610db6e/
807f2d70419959efdb87cf004610db6e
text
Text only
1
2019-05-25T11:34:18
True
False
False
/api/public/snipt/2409/
set-php-to-run-with-php5-in-htaccess
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>AddType x-mapp-php5 .php </span></pre></div> </td></tr></table>
htaccess, php

Text only

turn off php register_globals in htaccess

php_value register_globals 0
https://snipt.net/embed/a1cd815420c754adddb325beee78395c/
/raw/a1cd815420c754adddb325beee78395c/
a1cd815420c754adddb325beee78395c
text
Text only
1
2019-06-12T23:34:04
True
False
False
/api/public/snipt/2408/
turn-off-php-register_globals-in-htaccess
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>php_value register_globals 0 </span></pre></div> </td></tr></table>
htaccess, php

HTML+PHP

print drupal primary links with custom class

1
2
3
4
5
<div id="navigation">
	<?php if (isset($primary_links)) : ?>
		<?php print theme('links', $primary_links, array('class' => 'nav-links primary-nav-links')) ?>
	<?php endif; ?>
</div>
https://snipt.net/embed/88fc4073a9c00645089f02d0c780fca8/
/raw/88fc4073a9c00645089f02d0c780fca8/
88fc4073a9c00645089f02d0c780fca8
html+php
HTML+PHP
5
2019-05-23T12:43:48
True
False
False
/api/public/snipt/2399/
print-drupal-primary-links-with-custom-class
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;navigation&quot;</span><span class="p">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$primary_links</span><span class="p">))</span> <span class="o">:</span> <span class="cp">?&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nx">theme</span><span class="p">(</span><span class="s1">&#39;links&#39;</span><span class="p">,</span> <span class="nv">$primary_links</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;class&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;nav-links primary-nav-links&#39;</span><span class="p">))</span> <span class="cp">?&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
drupal, html, php

PHP

overriding a drupal theme function with a custom function

1
2
3
4
<?
nameofdifferentheme_name_of_theme_function($items){
  return 'dont display that crap!' . $items;
}
https://snipt.net/embed/422206916bc0de9dbd01903bab2f635b/
/raw/422206916bc0de9dbd01903bab2f635b/
422206916bc0de9dbd01903bab2f635b
php
PHP
4
2019-06-11T14:31:02
True
False
False
/api/public/snipt/2397/
overriding-a-drupal-theme-function-with-a-custom-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">nameofdifferentheme_name_of_theme_function</span><span class="p">(</span><span class="nv">$items</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="s1">&#39;dont display that crap!&#39;</span> <span class="o">.</span> <span class="nv">$items</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
drupal, php

PHP

how to call a theme function in drupal

<? theme('name_of_theme_function',$items);
https://snipt.net/embed/dc9702168615721a750230eb5f777603/
/raw/dc9702168615721a750230eb5f777603/
dc9702168615721a750230eb5f777603
php
PHP
1
2019-06-14T21:57:23
True
False
False
/api/public/snipt/2396/
how-to-call-a-theme-function-in-drupal
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> <span class="nx">theme</span><span class="p">(</span><span class="s1">&#39;name_of_theme_function&#39;</span><span class="p">,</span><span class="nv">$items</span><span class="p">);</span> </span></pre></div> </td></tr></table>
drupal, php

PHP

example of a default drupal theme function

1
2
3
4
5
<?
function theme_name_of_theme_function($items = NULL) {
  $output = 'hey, this is some output that gets generated when theme_name_of_theme_function($items) is called from somewhere';
  return $output;
}
https://snipt.net/embed/581e02657be24d26aeebcf3a81cbefcc/
/raw/581e02657be24d26aeebcf3a81cbefcc/
581e02657be24d26aeebcf3a81cbefcc
php
PHP
5
2019-05-27T18:04:45
True
False
False
/api/public/snipt/2395/
example-of-a-default-drupal-theme-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">theme_name_of_theme_function</span><span class="p">(</span><span class="nv">$items</span> <span class="o">=</span> <span class="k">NULL</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$output</span> <span class="o">=</span> <span class="s1">&#39;hey, this is some output that gets generated when theme_name_of_theme_function($items) is called from somewhere&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="nv">$output</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
drupal, php

PHP

how to register a drupal 6 theme function

1
2
3
4
5
6
7
8
<?
function name_of_module_theme() {
  return array(
    'name_of_theme_function' => array(
      'arguments' => array('items' => NULL)
    )
  );
}
https://snipt.net/embed/90153e18c041bb6d1ac98ce7224cc6e0/
/raw/90153e18c041bb6d1ac98ce7224cc6e0/
90153e18c041bb6d1ac98ce7224cc6e0
php
PHP
8
2019-06-12T06:05:44
True
False
False
/api/public/snipt/2394/
how-to-register-a-drupal-6-theme-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">name_of_module_theme</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="k">array</span><span class="p">(</span> </span><span id="L-4"><a name="L-4"></a> <span class="s1">&#39;name_of_theme_function&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span> </span><span id="L-5"><a name="L-5"></a> <span class="s1">&#39;arguments&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;items&#39;</span> <span class="o">=&gt;</span> <span class="k">NULL</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
drupal, php