snipt

Ctrl+h for KB shortcuts

PHP

remove trailing slash from last character of string (url)

1
2
3
4
5
6
7
function removeLastSlash($url)
	{
		if($url{strlen($url) - 1} == '/')
			return substr($url, 0, strlen($url) - 1);
		else
			return $url;
	}
https://snipt.net/embed/7801bc7dda6be439c19eb2ca9f09564b/
/raw/7801bc7dda6be439c19eb2ca9f09564b/
7801bc7dda6be439c19eb2ca9f09564b
php
PHP
7
2019-07-19T15:32:26
True
False
False
Feb 06, 2014 at 08:24 AM
/api/public/snipt/111420/
remove-trailing-slash-from-last-character-of-string-url
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">function removeLastSlash($url)</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> if($url{strlen($url) - 1} == &#39;/&#39;)</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> return substr($url, 0, strlen($url) - 1);</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> else</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> return $url;</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> }</span> </span></pre></div> </td></tr></table>
string

PHP

check keyword in string : strpos()

1
2
3
4
5
6
<?php
// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.
if ( strpos( $all_string , 'keyword' ) !== false ) 
{
	echo 'true ';
}
https://snipt.net/embed/7d2d9604d04d99c86a277981437e7546/
/raw/7d2d9604d04d99c86a277981437e7546/
7d2d9604d04d99c86a277981437e7546
php
PHP
6
2016-12-29T10:09:29
True
False
True
Aug 27, 2013 at 12:06 AM
/api/public/snipt/77238/
check-keyword-in-string-strpos
<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></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="c1">// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="p">(</span> <span class="nb">strpos</span><span class="p">(</span> <span class="nv">$all_string</span> <span class="p">,</span> <span class="s1">&#39;keyword&#39;</span> <span class="p">)</span> <span class="o">!==</span> <span class="k">false</span> <span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="s1">&#39;true &#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
change, replace, string