# 同样是写入内容到文件里，php只用一行代码，而OC。。。

**URL:** <https://www.shiqidu.com/t/topic/354>\
**Category:** 开发调优\
**Tags:** C-C-Obj-C\
**Created:** [2018 年1 月 3 日 14:27 UTC](https://www.shiqidu.com/t/topic/354 "2018-01-03T14:27:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Eureka](https://www.shiqidu.com/user_avatar/www.shiqidu.com/eureka/32/5_2.png) [@Eureka](https://www.shiqidu.com/u/Eureka)\
发布日期： [2018 年1 月 3 日 14:27 UTC](https://www.shiqidu.com/t/topic/354/1 "2018-01-03T14:27:49Z")

</div>

### OC

```c
// 文件写入  
NSString *str3 = @&quot;hello oc&quot;;  
NSString *path3 = @&quot;file:///Users/luz/Desktop/未命名文件夹/test.txt&quot;;  
path3 = [path3 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];  
NSURL *url3 = [NSURL URLWithString:path3];  
[str3 writeToURL:url3 atomically:YES encoding:NSUTF8StringEncoding error:nil];  

```

这方法名的长度可真长啊。。。

### php

```php
file_put_contents(&quot;/Users/luz/Desktop/未命名文件夹/test_1.txt&quot;, &quot;hello php&quot;)  

```

php果然是世界上最好的语言。。。
