回答編集履歴

2

誤記修正

2016/05/22 16:22

投稿

pi-chan
pi-chan

スコア5936

test CHANGED
@@ -92,7 +92,7 @@
92
92
 
93
93
 
94
94
 
95
- printf( $html, $item->Name, $item->Property->Yomi, str_replace ("-", "", $item->Property->Tel1), $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->PcUrl1 );
95
+ printf( $html, $item->Name, $item->Property->Yomi, str_replace("-", "", $item->Property->Tel1), $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->PcUrl1 );
96
96
 
97
97
  ```
98
98
 

1

追記

2016/05/22 16:22

投稿

pi-chan
pi-chan

スコア5936

test CHANGED
@@ -73,3 +73,47 @@
73
73
  イロイロなシミュレーターが公開されていますので、例えば下記ページなどを参考に、適当な物をダウンロードして試してみてください。
74
74
 
75
75
  [本当に使える! スマホ 【シュミレーター】 【エミュレーター】はこれだ - NAVER まとめ](http://matome.naver.jp/m/odai/2136992669579117701)
76
+
77
+
78
+
79
+ ---
80
+
81
+ (コメントに対する追記)
82
+
83
+
84
+
85
+ ```PHP
86
+
87
+ $html = '<tr><td>%1$s</td><td>%2$s</td><td><a href="tel:%3$s">%4$s</a></td><td>%5$s</td><td>%6$s</td><td>%7$s</td><td><a>%8$s"target="_blank"</a></td></tr>';
88
+
89
+
90
+
91
+ foreach ( $xml->Feature as $key => $item ) {
92
+
93
+
94
+
95
+ printf( $html, $item->Name, $item->Property->Yomi, str_replace ("-", "", $item->Property->Tel1), $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->PcUrl1 );
96
+
97
+ ```
98
+
99
+
100
+
101
+ 要するに、以前に記載した例だと
102
+
103
+ `<a href="tel:%3$s">%3$s</a>`
104
+
105
+ のようにタグの部分と画面表示の部分にAPIから取得した文字列をそのまま渡していましたが、
106
+
107
+ `<a href="tel:%3$s">%4$s</a>`
108
+
109
+ のように別々にして、`%3` の方には「03xxxxxxxx」、`%4` の方には「03-xxxx-xxxx」を渡すようにします。
110
+
111
+ そして、`%3` の方に渡す分は、APIから取得した文字列から [str_replace関数](http://php.net/manual/ja/function.str-replace.php) を使って「-」を削除してやれば良いだけです。
112
+
113
+
114
+
115
+ 上記の「例」は、コーディング方法として必ずしも良いお手本ではないですから、必ずご自身でしっかり理解した上でコーディングを行ってください。
116
+
117
+ PHPでプログラミングする上で文字列の加工は基本中の基本ですから、[PHP マニュアル](http://php.net/manual/ja/index.php) を再確認して、どんな事が出来るのかを把握してからプログラミングすることを強くオススメします。
118
+
119
+