{"id":1319,"date":"2011-09-14T13:17:52","date_gmt":"2011-09-14T11:17:52","guid":{"rendered":"http:\/\/www.karadere.com\/blog\/?p=1319"},"modified":"2011-09-14T13:17:52","modified_gmt":"2011-09-14T11:17:52","slug":"php-ile-web-service-yazmak-how-to-web-service-php","status":"publish","type":"post","link":"https:\/\/www.karadere.com\/blog\/php-ile-web-service-yazmak-how-to-web-service-php.html","title":{"rendered":"Php ile web service yazmak &#8211; How to web service php"},"content":{"rendered":"<p>A\u015fa\u011f\u0131da XML ve JSON \u00f6rnekli bir webservice \u00f6rne\u011fini sizin ile bayla\u015f\u0131yorum.\u00a0 web-service.php\u00a0 oalrka kaydettiginizi var sayal\u0131m<\/p>\n<p>XML i\u00e7in \u00e7a\u011f\u0131rma : <a href=\"http:\/\/sizindomain.com\/web-service.php?user=2&amp;num=10\">http:\/\/sizindomain.com\/web-service.php?user=2&amp;num=10<\/a><\/p>\n<p>JSON i\u00e7in \u00e7a\u011f\u0131rma : <a href=\"http:\/\/sizindomain.com\/web-service.php?user=2&amp;num=10&amp;format=json\">http:\/\/sizindomain.com\/web-service.php?user=2&amp;num=10&amp;format=json<\/a>\u00a0<\/p>\n<pre lang=\"Php\">\/* require the user as the parameter *\/\nif(isset($_GET['user']) &amp;&amp; intval($_GET['user'])) {\n\n  \/* soak in the passed variable or set our own *\/\n  $number_of_posts = isset($_GET['num']) ? intval($_GET['num']) : 10; \/\/10 is the default\n  $format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; \/\/xml is the default\n  $user_id = intval($_GET['user']); \/\/no default\n\n  \/* connect to the db *\/\n  $link = mysql_connect('localhost','username','password') or die('Cannot connect to the DB');\n  mysql_select_db('db_name',$link) or die('Cannot select the DB');\n\n  \/* grab the posts from the db *\/\n  $query = \"SELECT post_title, guid FROM wp_posts WHERE post_author = $user_id AND post_status = 'publish' ORDER BY ID DESC LIMIT $number_of_posts\";\n  $result = mysql_query($query,$link) or die('Errant query:  '.$query);\n\n  \/* create one master array of the records *\/\n  $posts = array();\n  if(mysql_num_rows($result)) {\n    while($post = mysql_fetch_assoc($result)) {\n      $posts[] = array('post'=&gt;$post);\n    }\n  }\n\n  \/* output in necessary format *\/\n  if($format == 'json') {\n    header('Content-type: application\/json');\n    echo json_encode(array('posts'=&gt;$posts));\n  }\n  else {\n    header('Content-type: text\/xml');\n    echo '';\n    foreach($posts as $index =&gt; $post) {\n      if(is_array($post)) {\n        foreach($post as $key =&gt; $value) {\n          echo '&lt;',$key,'&gt;';\n          if(is_array($value)) {\n            foreach($value as $tag =&gt; $val) {\n              echo '&lt;',$tag,'&gt;',htmlentities($val),'';\n            }\n          }\n          echo '';\n        }\n      }\n    }\n    echo '';\n  }\n\n  \/* disconnect from the db *\/\n  @mysql_close($link);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A\u015fa\u011f\u0131da XML ve JSON \u00f6rnekli bir webservice \u00f6rne\u011fini sizin ile bayla\u015f\u0131yorum.  web-service.php  oalrka kaydettiginizi var sayal\u0131m <\/p>\n<p>XML i\u00e7in \u00e7a\u011f\u0131rma : http:\/\/sizindomain.com\/web-service.php?user=2&#038;num=10<\/p>\n<p>JSON i\u00e7in \u00e7a\u011f\u0131rma : http:\/\/sizindomain.com\/web-service.php?user=2&#038;num=10&#038;format=json <\/p>\n<p><?php\n\n\/* require the user as the parameter *\/\nif(isset($_GET['user']) &amp;&amp; intval($_GET['user'])) {\n\n \/* soak in the passed variable or set our own *\/\n $number_of_posts = isset($_GET['num']) ? intval($_GET['num']) : 10; \/\/10 is the default\n $format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; \/\/xml is the default\n $user_id = intval($_GET['user']); \/\/no default\n\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[83,51],"tags":[235,1928,2235],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-php","category-soap-web-service","tag-php","tag-soap","tag-web-service","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"aioseo_notices":[],"views":5238,"_links":{"self":[{"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/comments?post=1319"}],"version-history":[{"count":0,"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.karadere.com\/blog\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}