<?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>EaseMarry Blogs &#187; Array</title>
	<atom:link href="http://www.easemarry.com/blog/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.easemarry.com/blog</link>
	<description>php and java code</description>
	<lastBuildDate>Sun, 09 Aug 2009 16:09:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google AJAX Language API php class</title>
		<link>http://www.easemarry.com/blog/google-ajax-language-api-php-class/</link>
		<comments>http://www.easemarry.com/blog/google-ajax-language-api-php-class/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 12:27:54 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[AjAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[9a]]></category>
		<category><![CDATA[Api]]></category>
		<category><![CDATA[Arbitrary Text]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Empty String]]></category>
		<category><![CDATA[Escape Sequences]]></category>
		<category><![CDATA[Gabe]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Http Server]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Match]]></category>
		<category><![CDATA[Php Language]]></category>
		<category><![CDATA[Return String]]></category>
		<category><![CDATA[String Function]]></category>
		<category><![CDATA[Text String]]></category>
		<category><![CDATA[Translate Text]]></category>
		<category><![CDATA[Translating Language]]></category>
		<category><![CDATA[Translation]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/?p=39</guid>
		<description><![CDATA[This class allows you to use the Google AJAX Translation API to translate arbitrary text to the many languages supported by the Google API.
Source versioning added to:
http://code.google.com/p/php-language-api/

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
&#60; ?php /** * Translating language with Google API * @author gabe@fijiwebdesign.com * @version $id$ * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/) *  * Google requires attribution [...]]]></description>
			<content:encoded><![CDATA[<p>This class allows you to use the Google AJAX Translation API to translate arbitrary text to the many languages supported by the Google API.</p>
<p>Source versioning added to:<br />
<a class="t" rel="nofollow" href="http://code.google.com/p/php-language-api/" target="_blank">http://code.google.com/p/php-language-api/</a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p39code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p392"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code" id="p39code2"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #009933; font-style: italic;">/** * Translating language with Google API * @author gabe@fijiwebdesign.com * @version $id$ * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/) *  * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding *  */</span><span style="color: #000000; font-weight: bold;">class</span> Google_Translate_API <span style="color: #009900;">&#123;</span> 	<span style="color: #009933; font-style: italic;">/**	 * Translate a piece of text with the Google Translate API	 * @return String	 * @param $text String	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin	 * @param $to String[optional] Language to translate $text to	 */</span>	<span style="color: #000000; font-weight: bold;">function</span> translate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&amp;q='</span><span style="color: #339933;">.</span><a href="http://www.php.net/rawurlencode"><span style="color: #990000;">rawurlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;langpair='</span><span style="color: #339933;">.</span><a href="http://www.php.net/rawurlencode"><span style="color: #990000;">rawurlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">.</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span>			<span style="color: #000088;">$url</span><span style="color: #339933;">,</span>			<span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>			<a href="http://www.php.net/stream_context_create"><span style="color: #990000;">stream_context_create</span></a><span style="color: #009900;">&#40;</span>				<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>					<span style="color: #0000ff;">'http'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>					<span style="color: #0000ff;">'method'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #339933;">,</span>					<span style="color: #0000ff;">'header'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Referer: http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>					<span style="color: #009900;">&#41;</span>				<span style="color: #009900;">&#41;</span>			<span style="color: #009900;">&#41;</span>		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/{<span style="color: #000099; font-weight: bold;">\&quot;</span>translatedText<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>([^<span style="color: #000099; font-weight: bold;">\&quot;</span>]+)<span style="color: #000099; font-weight: bold;">\&quot;</span>/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_unescapeUTF8EscapeSeq<span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #009900;">&#125;</span>		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>	<span style="color: #009900;">&#125;</span> 	<span style="color: #009933; font-style: italic;">/**	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes	 * @return UTF-8 String	 * @param $str String	 */</span>	<span style="color: #000000; font-weight: bold;">function</span> _unescapeUTF8EscapeSeq<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		<span style="color: #b1b100;">return</span> <a href="http://www.php.net/preg_replace_callback"><span style="color: #990000;">preg_replace_callback</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\\</span>\u([0-9a-f]{4})/i&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/create_function"><span style="color: #990000;">create_function</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return html_entity_decode(\'&amp;#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</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: #666666; font-style: italic;">// example usage$text = 'Welcome to my website.';$trans_text = Google_Translate_API::translate($text, '', 'it');if ($trans_text !== false) {	echo $trans_text;}  ?&gt;&lt; ?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Google_Translate_API <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> translate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&amp;q='</span><span style="color: #339933;">.</span><a href="http://www.php.net/rawurlencode"><span style="color: #990000;">rawurlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;langpair='</span><span style="color: #339933;">.</span><a href="http://www.php.net/rawurlencode"><span style="color: #990000;">rawurlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">.</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span>
			<span style="color: #000088;">$url</span><span style="color: #339933;">,</span>
			<span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
			<a href="http://www.php.net/stream_context_create"><span style="color: #990000;">stream_context_create</span></a><span style="color: #009900;">&#40;</span>
				<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'http'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'method'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'header'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Referer: http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/{<span style="color: #000099; font-weight: bold;">\&quot;</span>translatedText<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>([^<span style="color: #000099; font-weight: bold;">\&quot;</span>]+)<span style="color: #000099; font-weight: bold;">\&quot;</span>/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_unescapeUTF8EscapeSeq<span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> _unescapeUTF8EscapeSeq<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <a href="http://www.php.net/preg_replace_callback"><span style="color: #990000;">preg_replace_callback</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\\</span>\u([0-9a-f]{4})/i&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/create_function"><span style="color: #990000;">create_function</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return html_entity_decode(\'&amp;#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// example usage</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Welcome to my website.'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$trans_text</span> <span style="color: #339933;">=</span> Google_Translate_API<span style="color: #339933;">::</span><span style="color: #004000;">translate</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: #339933;">,</span> <span style="color: #0000ff;">'it'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trans_text</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$trans_text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/google-ajax-language-api-php-class/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Export RSS 1.0 or 2.0 feeds to an array</title>
		<link>http://www.easemarry.com/blog/export-rss-10-or-20-feeds-to-an-array/</link>
		<comments>http://www.easemarry.com/blog/export-rss-10-or-20-feeds-to-an-array/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 16:04:00 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Channel Description]]></category>
		<category><![CDATA[Description Language]]></category>
		<category><![CDATA[Item Description]]></category>
		<category><![CDATA[Language Channel]]></category>
		<category><![CDATA[Link Description]]></category>
		<category><![CDATA[Simplexml]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/export-rss-10-or-20-feeds-to-an-array/</guid>
		<description><![CDATA[
?View Code PHP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
&#60; ?php
/*     exportrss.php
*      Copyright 2007 Alec Hussey &#60;alec.hussey@gmail.com&#62;
*      This program is free software; you can redistribute it and/or modify
*      it under the terms of the GNU General Public License as published by
*   [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p38code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p385"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
</pre></td><td class="code" id="p38code5"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">/*     exportrss.php
*      Copyright 2007 Alec Hussey &lt;alec.hussey@gmail.com&gt;
*      This program is free software; you can redistribute it and/or modify
*      it under the terms of the GNU General Public License as published by
*      the Free Software Foundation; either version 2 of the License, or
*      (at your option) any later version.
*      This program is distributed in the hope that it will be useful,
*      but WITHOUT ANY WARRANTY; without even the implied warranty of
*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*      GNU General Public License for more details. *
*      You should have received a copy of the GNU General Public License
*      along with this program; if not, write to the Free Software
*      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
*      MA 02110-1301, USA.
*/</span>
<span style="color: #000000; font-weight: bold;">class</span> ExportRSS<span style="color: #009900;">&#123;</span>
	protected <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	protected <span style="color: #000088;">$channel</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	protected <span style="color: #000088;">$rawdata</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/simplexml_load_string"><span style="color: #990000;">simplexml_load_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 		<span style="color: #666666; font-style: italic;">// Parse the XML/RSS file</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span>		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;1.0&quot;</span><span style="color: #339933;">:</span>			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;title&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;link&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;description&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;image&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">image</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;items&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;textinput&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rowdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">textinput</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">&quot;title&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;link&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;description&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<a href="http://www.php.net/array_push"><span style="color: #990000;">array_push</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;2.0&quot;</span><span style="color: #339933;">:</span>			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;title&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;link&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;description&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;language&quot;</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;date&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;builddate&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastBuildDate</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;docs&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">docs</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;generator&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generator</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;editor&quot;</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">managingEditor</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;webmaster&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">webMaster</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">&quot;title&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;link&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;description&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;enclosure&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enclosure</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;date&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">&quot;guid&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<a href="http://www.php.net/array_push"><span style="color: #990000;">array_push</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ExportRSS::WARNING: invalid version was specified&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_raw_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rawdata</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_channel_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</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></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p38code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p386"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p38code6"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php 
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exportrss.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Parse XML/RSS 2.0 feed </span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExportRSS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.xml&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;2.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$channel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_channel_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;h3&gt;Channel&lt;/h3&gt;
&lt;strong&gt;Title:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['title']}</span> 
&lt;strong&gt;Date:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['date']}</span> 
&lt;strong&gt;Description:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['description']}</span> 
&lt;strong&gt;Editor:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['editor']}</span> 
&lt;strong&gt;Webmaster:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['webmaster']}</span> 
&lt;strong&gt;Language:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['language']}</span> 
&lt;strong&gt;Generator:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['generator']}</span> 
&lt;strong&gt;Link:&lt;/strong&gt; <span style="color: #006699; font-weight: bold;">{$channel['link']}</span> 
&nbsp;
&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;h3&gt;Feed Items&lt;/h3&gt;
&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; 
&nbsp;
        &lt;strong&gt;Title&lt;/strong&gt;: <span style="color: #006699; font-weight: bold;">{$item['title']}</span> 
        &lt;strong&gt;Date Published&lt;/strong&gt;: <span style="color: #006699; font-weight: bold;">{$item['date']}</span> 
        &lt;strong&gt;Description&lt;/strong&gt;: <span style="color: #006699; font-weight: bold;">{$item['description']}</span> 
        &lt;strong&gt;Link&lt;/strong&gt;: <span style="color: #006699; font-weight: bold;">{$item['link']}</span> 
&nbsp;
&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/export-rss-10-or-20-feeds-to-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Being Binary in SOAP</title>
		<link>http://www.easemarry.com/blog/being-binary-in-soap/</link>
		<comments>http://www.easemarry.com/blog/being-binary-in-soap/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 11:20:53 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Base64 Decode]]></category>
		<category><![CDATA[Base64 Encode]]></category>
		<category><![CDATA[Base64 Encoding]]></category>
		<category><![CDATA[Binary Data]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Data Path]]></category>
		<category><![CDATA[Input File]]></category>
		<category><![CDATA[Input Server]]></category>
		<category><![CDATA[Php Extension]]></category>
		<category><![CDATA[Php Ini]]></category>
		<category><![CDATA[Php Soap]]></category>
		<category><![CDATA[Remote Server]]></category>
		<category><![CDATA[Server Code]]></category>
		<category><![CDATA[Soap Wsdl]]></category>
		<category><![CDATA[Soapclient]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/being-binary-in-soap/</guid>
		<description><![CDATA[
Well, it might not be the best way to do it, but here&#8217;s a way I found to send binary data via PHP&#8217;s SOAP extension from one place to another:
Server:

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
function recieveFile&#40;$data&#41;&#123;
$data=base64_decode&#40;$data&#41;;
$path='/my/file/path/img_out.gif';
$fp=fopen&#40;$path,'w+'&#41;;
if&#40;$fp&#41;&#123; fwrite&#40;$fp,$data&#41;; fclose&#40;$fp&#41;; &#125;
return strlen&#40;$data&#41;.'written';
&#125;
$input = file_get_contents&#40;”php://input”);
$server = new SoapServer&#40;'http://[my url here]/binary.wsdl',array&#40;'encoding'=&#62;'ISO-8859-1'&#41;&#41;;
$server-&#62;addFunction&#40;'recieveFile'&#41;;
$server-&#62;handle&#40;&#41;;

and the Client:

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
ini_set&#40;&#34;soap.wsdl_cache_enabled&#34;, &#34;0&#34;&#41;;
//send binary data
$client=new SoapClient&#40;'http://[my url here]/binary.wsdl',array&#40;'encoding'=&#62;'ISO-8859-1'&#41;&#41;;
$data=file_get_contents&#40;'/my/file/path/img_to_send.gif'&#41;;
$ret=$client-&#62;recieveFile&#40;base64_encode&#40;$data&#41;&#41;;
print_r&#40;$ret&#41;;
&#91;/code&#93;
&#160;
It's pretty [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Well, it might not be the best way to do it, but here&#8217;s a way I found to send binary data via PHP&#8217;s SOAP extension from one place to another:</p>
<p><strong><a target="_blank" href="http://www.easemarry.com/blog">Server:</a></strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p20code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p209"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p20code9"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> recieveFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><a href="http://www.php.net/base64_decode"><span style="color: #990000;">base64_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$path</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'/my/file/path/img_out.gif'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fp</span><span style="color: #339933;">=</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'written'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span>”php<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//input”);</span>
<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapServer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://[my url here]/binary.wsdl'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'encoding'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'ISO-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'recieveFile'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a target="_blank" href="http://www.easemarry.com/blog">and the <strong>Client:</strong></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p20code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2010"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p20code10"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;soap.wsdl_cache_enabled&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//send binary data</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://[my url here]/binary.wsdl'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'encoding'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'ISO-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/my/file/path/img_to_send.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span><span style="color: #339933;">=</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">recieveFile</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/base64_encode"><span style="color: #990000;">base64_encode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span><span style="color: #339933;">/</span>code<span style="color: #009900;">&#93;</span>
&nbsp;
It<span style="color: #0000ff;">'s pretty basic - the client just reads in the file'</span>s information<span style="color: #339933;">,</span> runs it through a call to <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://php.net/base64_encode&quot;</span><span style="color: #339933;">&gt;</span>base64_encode<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> before it<span style="color: #0000ff;">'s sent off to the server. Once it'</span>s there a mirror call to <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://php.net/base64_decode&quot;</span><span style="color: #339933;">&gt;</span>base64_decode<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> gets the content back to normal and it<span style="color: #0000ff;">'s written out to the &quot;img_out.gif&quot; file on the remote server.
&nbsp;
It'</span>s probably not the best way to <span style="color: #b1b100;">do</span> it<span style="color: #339933;">,</span> but its one that I<span style="color: #0000ff;">'ve found that works quickly and easily. I tried to just send the binary data without base64 encoding it and it didn'</span>t want to cooperate <span style="color: #009900;">&#40;</span>it was only getting the first chunk of data<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> I don<span style="color: #0000ff;">'t know how well it'</span>ll perform with larger files<span style="color: #339933;">,</span> though <span style="color: #339933;">-</span> we shall see<span style="color: #339933;">.</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/being-binary-in-soap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle class &#8211; PHP</title>
		<link>http://www.easemarry.com/blog/oracle-class-php/</link>
		<comments>http://www.easemarry.com/blog/oracle-class-php/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 11:51:17 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Completeness]]></category>
		<category><![CDATA[Constructor Function]]></category>
		<category><![CDATA[Oracle 9i]]></category>
		<category><![CDATA[Oracle Class]]></category>
		<category><![CDATA[Oracle Home]]></category>
		<category><![CDATA[Php Class]]></category>
		<category><![CDATA[Putenv]]></category>
		<category><![CDATA[Sid]]></category>
		<category><![CDATA[Strange Error]]></category>
		<category><![CDATA[Zombie]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/?p=6</guid>
		<description><![CDATA[&#60;?php
class DB_Sql {
 var $Debug = false;
 var $Home = &#8220;/u01/app/oracle/ora90&#8243;;
 var $Remote = 1;
 /**
  * http://www.easemarry.com/blog
  * This Query will be sent directly after the first connection
  * Example:
  * var $ConnectQuery=&#8221;ALTER SESSION SET nls_date_language=german nls_date_format=&#8217;DD.MM.RRRR&#8217;&#8221;;
  * -&#62; Set the date format for this session, this is fine when your ora-role
  * cannot be altered
  */
 var $ConnectQuery=&#8221;;
 /**
  [...]]]></description>
			<content:encoded><![CDATA[<p>&lt;?php<br />
class DB_Sql {<br />
 var $Debug = false;<br />
 var $Home = &#8220;/u01/app/oracle/ora90&#8243;;<br />
 var $Remote = 1;<br />
 /**<br />
  * <a href="http://www.easemarry.com/blog">http://www.easemarry.com/blog</a><br />
  * This Query will be sent directly after the first connection<br />
  * Example:<br />
  * var $ConnectQuery=&#8221;ALTER SESSION SET nls_date_language=german nls_date_format=&#8217;DD.MM.RRRR&#8217;&#8221;;<br />
  * -&gt; Set the date format for this session, this is fine when your ora-role<br />
  * cannot be altered<br />
  */<br />
 var $ConnectQuery=&#8221;;<br />
 /**<br />
  * Due to a strange error with Oracle 9i, Apache and PHP4<br />
  * you don&#8217;t need to set the ENV &#8211; on my system Apache will change to a zombie, if I don&#8217;t set this to FALSE!<br />
  * Instead I set these ENV-vars before the startup of apache.<br />
  * If unsure try it out, if it works.�<br />
 .*/<br />
 var $OraPutEnv = true;</p>
<p> var $Database = &#8220;&#8221;;<br />
 var $User = &#8220;&#8221;;<br />
 var $Password = &#8220;&#8221;;</p>
<p> var $Link_ID = 0;<br />
 var $Query_ID = 0;<br />
 var $Record = array();<br />
 var $Row;</p>
<p> var $Errno = 0;<br />
 var $Error = &#8220;&#8221;;<br />
 var $ora_no_next_fetch=false;<br />
 /* copied from db_mysql for completeness */<br />
 /* public: identification constant. never change this. */<br />
 var $type = &#8220;oracle&#8221;;<br />
 var $revision = &#8220;Revision: 1.3&#8243;;<br />
 var $Halt_On_Error = &#8220;yes&#8221;; ## &#8220;yes&#8221; (halt with message), &#8220;no&#8221; (ignore errors quietly), &#8220;report&#8221; (ignore errror, but spit a warning)</p>
<p> /* public: constructor */<br />
 function DB_Sql($query = &#8220;&#8221;) {<br />
  $this-&gt;query($query);<br />
 }</p>
<p> /* public: some trivial reporting */<br />
 function link_id() {<br />
  return $this-&gt;Link_ID;<br />
 }</p>
<p> function query_id() {<br />
  return $this-&gt;Query_ID;<br />
 }</p>
<p> function connect() {<br />
  ## see above why we do this<br />
  if ($this-&gt;OraPutEnv) {<br />
   PutEnv(&#8221;ORACLE_SID=$this-&gt;Database&#8221;);<br />
   PutEnv(&#8221;ORACLE_HOME=$this-&gt;Home&#8221;);<br />
  }<br />
  if ( 0 == $this-&gt;Link_ID ) {<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;Connect()ing to $this-&gt;Database&#8230;&lt;br&gt;n&#8221;);<br />
   }<br />
   if($this-&gt;Remote) {<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;connect() $this-&gt;User/******@$this-&gt;Database&lt;br&gt;n&#8221;);<br />
    }<br />
    $this-&gt;Link_ID=ora_plogon<br />
    (&#8221;$this-&gt;User/$this-&gt;Password@$this-&gt;Database&#8221;,&#8221;");<br />
    /************** (comment by SSilk)<br />
    this dosn&#8217;t work on my system:<br />
    $this-&gt;Link_ID=ora_plogon<br />
    (&#8221;$this-&gt;User@$this-&gt;Database.world&#8221;,&#8221;$this-&gt;Password&#8221;);<br />
    ***************/<br />
   } else {<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;connect() $this-&gt;User, $this-&gt;Password &lt;br&gt;n&#8221;);<br />
    }<br />
    $this-&gt;Link_ID=ora_plogon(&#8221;$this-&gt;User&#8221;,&#8221;$this-&gt;Password&#8221;);<br />
    /* (comment by SSilk: don&#8217;t know how this could work, but I leave this untouched!) */<br />
   }<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;connect() Link_ID: $this-&gt;Link_ID&lt;br&gt;n&#8221;);<br />
   }<br />
   if (!$this-&gt;Link_ID) {<br />
    $this-&gt;halt(&#8221;connect() Link-ID == false &#8221; .<br />
    &#8221;($this-&gt;Link_ID), ora_plogon failed&#8221;);<br />
   } else {<br />
    //echo &#8220;commit on&lt;p&gt;&#8221;;<br />
    ora_commiton($this-&gt;Link_ID);<br />
   }<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;connect() Obtained the Link_ID: $this-&gt;Link_ID&lt;br&gt;n&#8221;);<br />
   }<br />
   ## Execute Connect Query<br />
   if ($this-&gt;ConnectQuery) {<br />
    $this-&gt;query($this-&gt;ConnectQuery);<br />
   }<br />
  }<br />
 }</p>
<p> ## In order to increase the # of cursors per system/user go edit the<br />
 ## init.ora file and increase the max_open_cursors parameter. Yours is on<br />
 ## the default value, 100 per user.<br />
 ## We tried to change the behaviour of query() in a way, that it tries<br />
 ## to safe cursors, but on the other side be carefull with this, that you<br />
 ## don&#8217;t use an old result.<br />
 ##<br />
 ## You can also make extensive use of -&gt;disconnect()!<br />
 ## The unused QueryIDs will be recycled sometimes.</p>
<p> function query($Query_String)<br />
 {</p>
<p>  /* No empty query please. */<br />
  if (empty($Query_String))<br />
  {<br />
   return 0;<br />
  }</p>
<p>  $this-&gt;connect();<br />
  $this-&gt;lastQuery=$Query_String;</p>
<p>  if (!$this-&gt;Query_ID) {<br />
   $this-&gt;Query_ID= ora_open($this-&gt;Link_ID);<br />
  }<br />
  if($this-&gt;Debug) {<br />
   printf(&#8221;Debug: query = %s&lt;br&gt;n&#8221;, $Query_String);<br />
   printf(&#8221;&lt;br&gt;Debug: Query_ID: %d&lt;br&gt;n&#8221;, $this-&gt;Query_ID);<br />
  }</p>
<p>  if(!@ora_parse($this-&gt;Query_ID,$Query_String)) {<br />
   $this-&gt;Errno=ora_errorcode($this-&gt;Query_ID);<br />
   $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;ora_parse() failed:&lt;BR&gt;$Query_String&lt;BR&gt;&lt;small&gt;Snap &amp; paste this to sqlplus!&lt;/SMALL&gt;&#8221;);<br />
  } elseif (!@ora_exec($this-&gt;Query_ID)) {<br />
   $this-&gt;Errno=ora_errorcode($this-&gt;Query_ID);<br />
   $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;n$Query_Stringn&lt;BR&gt;&lt;small&gt;Snap &amp; paste this to sqlplus!&lt;/SMALL&gt;&#8221;);<br />
  }</p>
<p>  $this-&gt;Row=0;</p>
<p>  if(!$this-&gt;Query_ID) {<br />
   $this-&gt;halt(&#8221;Invalid SQL: &#8220;.$Query_String);<br />
  }</p>
<p>  return $this-&gt;Query_ID;<br />
 }</p>
<p> function next_record() {<br />
  if (!$this-&gt;ora_no_next_fetch &amp;&amp;<br />
  0 == ora_fetch($this-&gt;Query_ID)) {<br />
   if ($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;next_record(): ID: %d Row: %d&lt;br&gt;n&#8221;,<br />
    $this-&gt;Query_ID,$this-&gt;Row+1);<br />
    // more info for $this-&gt;Row+1 is $this-&gt;num_rows(),<br />
    // but dosn&#8217;t work in all cases (complicated selects)<br />
    // and it is very slow here<br />
   }<br />
   $this-&gt;Row +=1;</p>
<p>   $errno=ora_errorcode($this-&gt;Query_ID);<br />
   if(1403 == $errno) { # 1043 means no more records found<br />
    $this-&gt;Errno=0;<br />
    $this-&gt;Error=&#8221;";<br />
    $this-&gt;disconnect();<br />
    $stat=0;<br />
   } else {<br />
    $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
    $this-&gt;Errno=$errno;<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;%d Error: %s&#8221;,<br />
     $this-&gt;Errno,<br />
     $this-&gt;Error);<br />
    }<br />
    $stat=0;<br />
   }<br />
  } else {<br />
   $this-&gt;ora_no_next_fetch=false;<br />
   for($ix=0;$ix&lt;ora_numcols($this-&gt;Query_ID);$ix++) {<br />
    $col=strtolower(ora_columnname($this-&gt;Query_ID,$ix));<br />
    $value=ora_getcolumn($this-&gt;Query_ID,$ix);<br />
    $this-&gt;Record[ "$col" ] = $value;<br />
    $this-&gt;Record[ $ix ] = $value;<br />
    #DBG echo&#8221;&lt;b&gt;[$col]&lt;/b&gt;: $value &lt;br&gt;n&#8221;;<br />
   }<br />
   $stat=1;<br />
  }</p>
<p>  return $stat;<br />
 }</p>
<p> ## seek() works only for $pos &#8211; 1 and $pos<br />
 ## Perhaps I make a own implementation, but my<br />
 ## opinion is, that this should be done by PHP3<br />
 function seek($pos) {<br />
  if ($this-&gt;Row &#8211; 1 == $pos) {<br />
   $this-&gt;ora_no_next_fetch=true;<br />
  } elseif ($this-&gt;Row == $pos ) {<br />
   ## do nothing<br />
  } else {<br />
   $this-&gt;halt(&#8221;Invalid seek(): Position is cannot be handled by API.&lt;BR&gt;&#8221;.<br />
   &#8221;Only a seek to the last element is allowed in this version&lt;BR&gt;&#8221;.<br />
   &#8221;Difference too big. Wanted: $pos Current pos: $this-&gt;Row&#8221;);<br />
  }<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: seek = $pos&lt;BR&gt;&#8221;;<br />
  $this-&gt;Row=$pos;<br />
 }</p>
<p> function lock($table, $mode = &#8220;write&#8221;) {<br />
  if ($mode == &#8220;write&#8221;) {<br />
   $result = ora_do($this-&gt;Link_ID, &#8220;lock table $table in row exclusive mode&#8221;);<br />
  } else {<br />
   $result = 1;<br />
  }<br />
  return $result;<br />
 }</p>
<p> function unlock() {<br />
  return ora_do($this-&gt;Link_ID, &#8220;commit&#8221;);<br />
 }</p>
<p> // Important note: This function dosn&#8217;t work with Oracle-Database-Links!<br />
 // You are free to get a better method. :)<br />
 function metadata($table,$full=false) {<br />
  $count = 0;<br />
  $id = 0;<br />
  $res = array();</p>
<p>  /*<br />
  * Due to compatibility problems with Table we changed the behavior<br />
  * of metadata();<br />
  * depending on $full, metadata returns the following values:<br />
  *<br />
  * &#8211; full is false (default):<br />
  * $result[]:<br />
  * [0]["table"] table name<br />
  * [0]["name"] field name<br />
  * [0]["type"] field type<br />
  * [0]["len"] field length<br />
  * [0]["flags"] field flags (&#8221;NOT NULL&#8221;, &#8220;INDEX&#8221;)<br />
  * [0]["format"] precision and scale of number (eg. &#8220;10,2&#8243;) or empty<br />
  * [0]["index"] name of index (if has one)<br />
  * [0]["chars"] number of chars (if any char-type)<br />
  *<br />
  * &#8211; full is true<br />
  * $result[]:<br />
  * ["num_fields"] number of metadata records<br />
  * [0]["table"] table name<br />
  * [0]["name"] field name<br />
  * [0]["type"] field type<br />
  * [0]["len"] field length<br />
  * [0]["flags"] field flags (&#8221;NOT NULL&#8221;, &#8220;INDEX&#8221;)<br />
  * [0]["format"] precision and scale of number (eg. &#8220;10,2&#8243;) or empty<br />
  * [0]["index"] name of index (if has one)<br />
  * [0]["chars"] number of chars (if any char-type)<br />
  * [0]["php_type"] the correspondig PHP-type<br />
  * [0]["php_subtype"] the subtype of PHP-type<br />
  * ["meta"][field name] index of field named &#8220;field name&#8221;<br />
  * This could used, if you have the name, but no index-num &#8211; very fast<br />
  * Test: if (isset($result['meta']['myfield'])) {} &#8230;<br />
  */</p>
<p>  $this-&gt;connect();</p>
<p>  ## This is a RIGHT OUTER JOIN: &#8220;(+)&#8221;, if you want to see, what<br />
  ## this query results try the following:<br />
  ## $table = new Table; $db = new my_DB_Sql; # you have to make<br />
  ## # your own class<br />
  ## $table-&gt;show_results($db-&gt;query(see query vvvvvv))<br />
  ##<br />
  $this-&gt;query(&#8221;SELECT T.table_name,T.column_name,T.data_type,&#8221;.<br />
  &#8221;T.data_length,T.data_precision,T.data_scale,T.nullable,&#8221;.<br />
  &#8221;T.char_col_decl_length,I.index_name&#8221;.<br />
  &#8221; FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I&#8221;.<br />
  &#8221; WHERE T.column_name=I.column_name (+)&#8221;.<br />
  &#8221; AND T.table_name=I.table_name (+)&#8221;.<br />
  &#8221; AND T.table_name=UPPER(&#8217;$table&#8217;) ORDER BY T.column_id&#8221;);</p>
<p>  $i=0;<br />
  while ($this-&gt;next_record()) {<br />
   $res[$i]["table"] = $this-&gt;Record[table_name];<br />
   $res[$i]["name"] = strtolower($this-&gt;Record[column_name]);<br />
   $res[$i]["type"] = $this-&gt;Record[data_type];<br />
   $res[$i]["len"] = $this-&gt;Record[data_length];<br />
   if ($this-&gt;Record[index_name]) $res[$i]["flags"] = &#8220;INDEX &#8220;;<br />
   $res[$i]["flags"] .= ( $this-&gt;Record[nullable] == &#8216;N&#8217;) ? &#8221; : &#8216;NOT NULL&#8217;;<br />
   $res[$i]["format"]= (int)$this-&gt;Record[data_precision].&#8221;,&#8221;.<br />
   (int)$this-&gt;Record[data_scale];<br />
   if (&#8221;0,0&#8243;==$res[$i]["format"]) $res[$i]["format"]=&#8221;;<br />
   $res[$i]["index"] = $this-&gt;Record[index_name];<br />
   $res[$i]["chars"] = $this-&gt;Record[char_col_decl_length];<br />
   if ($full) {<br />
    $j=$res[$i]["name"];<br />
    $res["meta"][$j] = $i;<br />
    $res["meta"][strtoupper($j)] = $i;<br />
    switch ($res[$i]["type"]) {<br />
     case &#8220;VARCHAR2&#8243; :<br />
     case &#8220;VARCHAR&#8221; :<br />
     case &#8220;CHAR&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;";<br />
      break;<br />
     case &#8220;DATE&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;date&#8221;;<br />
      break;<br />
     case &#8220;BLOB&#8221; :<br />
     case &#8220;CLOB&#8221; :<br />
     case &#8220;BFILE&#8221; :<br />
     case &#8220;RAW&#8221; :<br />
     case &#8220;LONG&#8221; :<br />
     case &#8220;LONG RAW&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;blob&#8221;;<br />
      break;<br />
     case &#8220;NUMBER&#8221; :<br />
      if ($res[$i]["format"]) {<br />
       $res["php_type"]=&#8221;double&#8221;;<br />
       $res["php_subtype"]=&#8221;";<br />
      } else {<br />
       $res["php_type"]=&#8221;int&#8221;;<br />
       $res["php_subtype"]=&#8221;";<br />
      }<br />
      break;<br />
     default :<br />
      $this-&gt;halt(&#8221;metadata(): Type is not a valid value: &#8216;$res[$i][type]&#8216;&#8221;);<br />
      break;<br />
    }<br />
   }<br />
   if ($full) $res["meta"][$res[$i]["name"]] = $i;<br />
   $i++;<br />
  }<br />
  if ($full) $res["num_fields"]=$i;<br />
  # $this-&gt;disconnect();<br />
  return $res;<br />
 }</p>
<p> ## THIS FUNCTION IS UNSTESTED!<br />
 function affected_rows() {<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: affected_rows=&#8221;. ora_numrows($this-&gt;Query_ID).&#8221;&lt;BR&gt;&#8221;;<br />
  return ora_numrows($this-&gt;Query_ID);<br />
 }</p>
<p> ## Known bugs: It will not work for SELECT DISTINCT and any<br />
 ## other constructs which are depending on the resulting rows.<br />
 ## So you *really need* to check every query you make, if it<br />
 ## will work with it!<br />
 ##<br />
 ## Also, for a qualified replacement you need to parse the<br />
 ## selection, cause this will fail: &#8220;SELECT id, from FROM &#8230;&#8221;).<br />
 ## &#8220;from&#8221; is &#8211; as far as I know a keyword in Oracle, so it can<br />
 ## only be used in this way. But you have been warned.<br />
 function num_rows() {<br />
  $curs=ora_open($this-&gt;Link_ID);</p>
<p>  ## this is the important part and it is also the HACK!<br />
  if (eregi(&#8221;^[[:space:]]*SELECT[[:space:]]&#8221;,$this-&gt;lastQuery) )<br />
  {</p>
<p>   # This works for all?? cases, including SELECT DISTINCT case.<br />
   # We just make select count(*) from original sql expression<br />
   # and remove ORDER BY (if any) for speed<br />
   # I like regular expressions too ;-)))<br />
   $q = sprintf(&#8221;SELECT COUNT(*) FROM (%s)&#8221;,<br />
   @eregi_Replace(&#8221;ORDER[[:space:]]+BY[^)]*()*)&#8221;, &#8220;\1&#8243;,<br />
   $this-&gt;lastQuery)<br />
   );</p>
<p>   # works also for subselects:<br />
   # if (eregi(&#8221;[[:space:]]+FROM([[:space:]]+.*[[:space:]]+FROM)&#8221;,$this-&gt;lastQuery,$r))<br />
   # $areplace=$r[1];<br />
   # $q=eregi_Replace(&#8221;^[[:space:]]*SELECT[[:space:]]+&#8221;.<br />
   # &#8220;.*[[:space:]]+FROM&#8221;,<br />
   # &#8220;SELECT COUNT(*) FROM$areplace&#8221;,<br />
   # $this-&gt;lastQuery);</p>
<p>   if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: num_rows: $q&lt;BR&gt;&#8221;;</p>
<p>   ORA_parse($curs,$q);<br />
   ORA_exec($curs);<br />
   ORA_fetch($curs);<br />
   $result = ORA_getcolumn($curs,0);<br />
   ORA_close($curs);<br />
   if ($this-&gt;Debug)<br />
   {<br />
    echo &#8220;&lt;BR&gt;Debug: ID &#8220;.$this-&gt;QueryID.<br />
    &#8221; num_rows=&#8221;. $result .&#8221;&lt;BR&gt;&#8221;;<br />
   }<br />
   return $result;<br />
  }<br />
  else<br />
  {<br />
   $this-&gt;halt(&#8221;Last Query was not a SELECT: $this-&gt;lastQuery&#8221;);<br />
  }<br />
 }</p>
<p> function num_fields() {<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: num_fields=&#8221;. ora_numcols($this-&gt;Query_ID) . &#8220;&lt;BR&gt;&#8221;;<br />
  return ora_numcols($this-&gt;Query_ID);<br />
 }</p>
<p> function nf() {<br />
  return $this-&gt;num_rows();<br />
 }</p>
<p> function np() {<br />
  print $this-&gt;num_rows();<br />
 }</p>
<p> function f($Name) {<br />
  return $this-&gt;Record[$Name];<br />
 }</p>
<p> function p($Name) {<br />
  print $this-&gt;Record[$Name];<br />
 }</p>
<p> /* public: sequence number */<br />
 function nextid($seq_name)<br />
 {<br />
  $this-&gt;connect();</p>
<p>  /* Independent Query_ID */<br />
  $Query_ID = ora_open($this-&gt;Link_ID);</p>
<p>  if(!@ora_parse($Query_ID,&#8221;SELECT $seq_name.NEXTVAL FROM DUAL&#8221;))<br />
  {<br />
   // There is no such sequence yet, then create it<br />
   if(!@ora_parse($Query_ID,&#8221;CREATE SEQUENCE $seq_name&#8221;)<br />
   ||<br />
   !@ora_exec($Query_ID)<br />
   )<br />
   {<br />
    $this-&gt;halt(&#8221;&lt;BR&gt; nextid() function &#8211; unable to create sequence&#8221;);<br />
    return 0;<br />
   }<br />
   @ora_parse($Query_ID,&#8221;SELECT $seq_name.NEXTVAL FROM DUAL&#8221;);<br />
  }<br />
  if (!@ora_exec($Query_ID)) {<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;ora_exec() failed:&lt;BR&gt;nextID function&#8221;);<br />
  }<br />
  if (@ora_fetch($Query_ID) ) {<br />
   $next_id = ora_getcolumn($Query_ID, 0);<br />
  }<br />
  else {<br />
   $next_id = 0;<br />
  }<br />
  if ( $Query_ID &gt; 0 ) {<br />
   ora_close($Query_ID);<br />
  }</p>
<p>  return $next_id;<br />
 }</p>
<p> function disconnect() {<br />
  if($this-&gt;Debug) {<br />
   echo &#8220;Debug: Disconnecting $this-&gt;Query_ID&#8230;&lt;br&gt;n&#8221;;<br />
  }<br />
  if ( $this-&gt;Query_ID &lt; 1 ) {<br />
   echo &#8220;&lt;B&gt;Warning&lt;/B&gt;: disconnect(): Cannot free ID $this-&gt;Query_IDn&#8221;;<br />
   # return();<br />
  }<br />
  ora_close($this-&gt;Query_ID);<br />
  $this-&gt;Query_ID=0;<br />
 }</p>
<p> /* private: error handling */<br />
 function halt($msg) {<br />
  if ($this-&gt;Halt_On_Error == &#8220;no&#8221;)<br />
  return;</p>
<p>  $this-&gt;haltmsg($msg);</p>
<p>  if ($this-&gt;Halt_On_Error != &#8220;report&#8221;)<br />
  die(&#8221;Session halted.&#8221;);<br />
 }</p>
<p> function haltmsg($msg) {<br />
  printf(&#8221;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;b&gt;Database error:&lt;/b&gt; %s&lt;br&gt;n&#8221;, $msg);<br />
  printf(&#8221;&lt;b&gt;Oracle Error&lt;/b&gt;: %s (%s)&lt;br&gt;n&#8221;,<br />
  $this-&gt;Errno,<br />
  $this-&gt;Error);<br />
 }</p>
<p> function table_names() {<br />
  $this-&gt;connect();<br />
  $this-&gt;query(&#8221;<br />
SELECT table_name,tablespace_name<br />
FROM user_tables&#8221;);<br />
  $i=0;<br />
  while ($this-&gt;next_record())<br />
  {<br />
   $info[$i]["table_name"] =$this-&gt;Record["table_name"];<br />
   $info[$i]["tablespace_name"]=$this-&gt;Record["tablespace_name"];<br />
   $i++;<br />
  }<br />
  return $info;<br />
 }<br />
 // Some transaction support<br />
 // Methods are used in ct_oracle.inc<br />
 function begin_transaction()<br />
 {<br />
  $this-&gt;connect();<br />
  // Now, disable autocommit<br />
  Ora_CommitOff($this-&gt;Link_ID);<br />
  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;BEGIN TRANSACTION&lt;BR&gt;&#8221;;<br />
  }<br />
 }<br />
 function end_transaction()<br />
 {<br />
  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;BEGIN TRANSACTION&lt;BR&gt;&#8221;;<br />
  }</p>
<p>  $res = 1;<br />
  if(!@Ora_Commit($this-&gt;Link_ID))<br />
  {<br />
   Ora_CommitOn($this-&gt;Link_ID);<br />
   $this-&gt;halt(&#8221;Unable to finish transaction&#8221;);<br />
   $res = 0;<br />
  }<br />
  // Enable autocommit again<br />
  Ora_CommitOn($this-&gt;Link_ID);</p>
<p>  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;END TRANSACTION : $res&lt;BR&gt;&#8221;;<br />
  }<br />
  return $res;<br />
 }<br />
}<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/oracle-class-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

