<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ersin Acar &#187; string</title>
	<atom:link href="http://ersinacar.com/tag/string/feed" rel="self" type="application/rss+xml" />
	<link>http://ersinacar.com</link>
	<description>PHP and Web Technologies Freak</description>
	<lastBuildDate>Fri, 14 May 2010 11:57:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Remove last char of string in PHP</title>
		<link>http://ersinacar.com/remove-last-char-of-string-in-php_138.html</link>
		<comments>http://ersinacar.com/remove-last-char-of-string-in-php_138.html#comments</comments>
		<pubDate>Sat, 30 May 2009 17:18:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=138</guid>
		<description><![CDATA[Simple and clear;

substr_replace&#40;$string ,&#34;&#34;,-1&#41;;

]]></description>
			<content:encoded><![CDATA[<p>Simple and clear;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">substr_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/remove-last-char-of-string-in-php_138.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searching strings in a multi-dimensional array</title>
		<link>http://ersinacar.com/searching-strings-in-a-multi-dimensional-array_103.html</link>
		<comments>http://ersinacar.com/searching-strings-in-a-multi-dimensional-array_103.html#comments</comments>
		<pubDate>Tue, 12 May 2009 21:45:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[multi-dimensional]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=103</guid>
		<description><![CDATA[I&#8217;m working on a security and trying to make searches in a multi-dimensional array
Here is the function;

&#60;?php
function multi_array_search&#40;$needle, $haystack, $key, &#38;$result, $searchlevel = 0&#41; &#123; 
  while&#40;is_array&#40;$haystack&#41; &#38;&#38; isset&#40;$haystack&#91;key&#40;$haystack&#41;&#93;&#41;&#41; &#123;
    if&#40;$searchlevel == 0 &#38;&#38; key&#40;$haystack&#41; == $key &#38;&#38; $haystack&#91;$key&#93; == $needle&#41; &#123;
      $result = $haystack;
  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a security and trying to make searches in a multi-dimensional array<br />
Here is the function;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> multi_array_search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$needle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$haystack</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #000088;">$searchlevel</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$searchlevel</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$haystack</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$needle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$haystack</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$searchlevel</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      multi_array_search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$needle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$haystack</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #000088;">$searchlevel</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #990000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Example;<br />
2-dimensional array, search by both key and value<br />
$arr1 = array(<br />
  1 => array(&#8216;id&#8217; => 1, &#8216;name&#8217; => &#8216;Ersin&#8217;, &#8216;gender&#8217; => &#8216;male&#8217;),<br />
  &#8230;<br />
  12 => array(&#8216;id&#8217; => 12, &#8216;name&#8217; => &#8216;Emel&#8217;, &#8216;gender&#8217; => &#8216;female&#8217;),<br />
);</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> array_search_in_level<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Emel'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>$result is:<br />
array(<br />
  &#8216;id&#8217; => int 12<br />
  &#8216;name&#8217; => string &#8216;Emel&#8217; (length=4)<br />
  &#8216;gender&#8217; => string &#8216;female&#8217; (length=4)<br />
) </p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/searching-strings-in-a-multi-dimensional-array_103.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortening a string in PHP</title>
		<link>http://ersinacar.com/shortening-a-string-in-php_31.html</link>
		<comments>http://ersinacar.com/shortening-a-string-in-php_31.html#comments</comments>
		<pubDate>Tue, 07 Apr 2009 15:13:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[shortening]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=31</guid>
		<description><![CDATA[
1
2
3
4
5
6
7
8
9
10
11
    function ShortText&#40;$text&#41; &#123;
        // display char lenght
        $chars = 10;
        $text = $text.&#34; &#34;;
        $text = substr&#40;$text,0,$chars&#41;;
       [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">function</span> ShortText<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// display char lenght</span>
        <span style="color: #000088;">$chars</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$text</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$text</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;...&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// You can give a link here</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//usage;</span>
<span style="color: #b1b100;">echo</span> ShortText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;it's a very  very very very very very very longggggggggggggg text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/shortening-a-string-in-php_31.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
