utf8的数据库,存入表情符,会出错

Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F...' for column 'content'


错误的解决办法:

引用
4 byte Unicode characters aren't yet widely used, so not every application out there fully supports them. MySQL 5.5 works fine with 4 byte characters when properly configured – check if your other components can work with them as well.

Here's a few other things to check out:

Make sure all your tables' default character sets and text fields are converted to utf8mb4, in addition to setting the client & server character sets, e.g. ALTER TABLE mytable charset=utf8mb4, MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4; and so on.

If your data is already in the utf8 character set, it should convert to utf8mb4 in place without any problems. As always, back up your data before trying!

Also make sure your app layer sets its database connections' character set to utf8mb4. Double-check this is actually happening – if you're running an older version of your chosen framework's mysql client library, it may not have been compiled with utf8mb4 support and it won't set the charset properly. If not, you may have to update it or compile it yourself.

When viewing your data through the mysql client, make sure you're on a machine that can display emoji, and run a SET NAMES utf8mb4 before running any queries.

Once every level of your application can support the new characters, you should be able to use them without any corruption.


总结就是,表结构改为支持4字节的unicode,数据库连接也用这个字符集哦,证明是可行的。
如果别的地方不支持,可以考虑去掉这些字符:

引用
Since 4-byte UTF-8 sequences always start with the bytes 0xF0-0xF7, the following should work:

$str = preg_replace('/[\xF0-\xF7].../s', '', $str);
Alternatively, you could use preg_replace in UTF-8 mode but this will probably be slower:

$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
This works because 4-byte UTF-8 sequences are used for code points in the supplementary Unicode planes starting from 0x10000.


参考来源:
http://stackoverflow.com/q...
http://stackoverflow.com/q...
1、验证ppp
用cat命令检查是否开启ppp,一般服务器都是开启的,除了特殊的VPS主机之外。
[root@localhost1 /]# cat /dev/ppp
cat: /dev/ppp: No such device or address

cat出现上面结果,则说明ppp是开启的,可以正常的配置pptp了。

2、安装PPP
[root@localhost1 /]# yum -y install ppp iptables

iptables一般情况默认都是系统装好后就已经有了,安装iptables是为了做NAT,让PPTP客户端能够通过PPTP服务器上外网。

3、安装PPTP
[root@localhost1 ~]# rpm -ivh pptpd-1.3.4-2.el6.x86_64.rpm

上面是针对64位系统安装的,这个包不能yum安装需要自己到网上下载支持32位或64位系统的rpm包。

阿权注:yum -y install pptpd 也是可以的,事先加入yum源
rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm


4、配置pptp
[root@localhost1 /]# vi /etc/pptpd.conf

在最底下添加下面两行,localip是pptp服务器端IP,remoteip是客户端获取的IP地址范围
localip 192.168.100.100
remoteip 192.168.100.101-110


修改options.pptpd文件
[root@localhost1 /]# vi /etc/ppp/options.pptpd

打开后,找到下面字段,并修改成你想要为VPN用户分配的dns服务器
ms-dns 8.8.8.8
ms-dns 8.8.4.4


添加vpn的帐号和密码
[root@localhost1 /]# vi /etc/ppp/chap-secrets

一行添加一个账号,每个帐号需要添加的4个字段,分别为:用户名、服务、密码、分配的ip地址(如果IP为*,则表示随机分配,分配范围采用pptp.conf中的设置)
# client server secret IP addresses
hmj pptpd hmj123 *

5、开启ip转发
[root@localhost1 /]# vi /etc/sysctl.conf

把net.ipv4.ip_forward的值改为1,

保存退出,并执行下面命令使内核配置生效:
[root@localhost1 /]# sysctl -p

6、配置iptables转发
[root@localhost1 /]# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --to-source 58.33.244.126

这条命令是让192.168.100.0这个段的ip地址,可以通过58.33.244.126这个公网IP访问外网。
你需要将192.168.100.0/24替换成你在pptp.conf中设置的ip段和子网掩码,将58.33.244.126替换成你服务器自己的公网ip地址,否则拨上来的用户只能访问内网。

阿权注:
如果有多个网卡,或者出口ip不稳定,可以用这个
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE


保存iptables配置
[root@localhost1 /]# service iptables save

7、启动服务
[root@localhost1 /]# service pptpd start
[root@localhost1 /]# service iptables start
#将服务配置为开机自动启动
[root@localhost1 /]# chkconfig pptpd on
[root@localhost1 /]# chkconfig iptables on


到此配置已经完毕,可以用普通PC建立VPN(加密方式为默认)连接来测试了。。

转自: http://www.heminjie.com/system/linux/307.html
刚才看到推特上有人说起SSL证书:

月光博客 ‏@williamlong
SSL证书申请机构:土豪级Verisign,屌丝级:Godaddy、Namecheap、cheapssl;免费的:startssl


SSL证书很多是需要购买的,有年费。
免费的是有使用时间限制,为了安全起见,还是有个SSL加密会比较好哦,免费的也可以使用一两年。

国内有一家 wosign 也有免费的申请,自己网站使用是没有问题的,至少是有保障。
https://buy.wosign.com/fre...

按提示申请很方便快捷,试用过正常。
startSSL也有使用步骤的说明,自己可以尝试。

wosign下载证书后,还很人性的把一些web软件需要的文件都打包了,比如nginx的
把文件上传到服务器,可以开启nginx的ssl
前提是,安装openssl和编译nginx时有包含ssl,否则会提示:
unknown directive "ssl"

安装openssl:
yum install openssl openssl-devel

nginx的编译:

./configure  --prefix=/Data/apps/nginx \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--add-module=ngx_cache_purge-2.1 \
&& make && make install


这里我有个ngx_cache_purge,不需要就去掉就可以,需要是可以在官网找到的,清理缓存用

nginx配置:

server {
    listen 443;
    server_name aslibra.com;
    ssl on;
    ssl_certificate  1_aslibra.com_bundle.crt;
    ssl_certificate_key  2_aslibra.com.key;
}


文件是相对目录,或者绝对目录,找到就可以
其他php之类的配置是一样的,这里仅包括简单配置
解析JSON数据,转换为NSData格式

            NSError *jsonError;
            NSData *objectData = [content2 dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:objectData
                                                                 options:NSJSONReadingMutableContainers
                                                                   error:&jsonError];


数值转换为字符串

    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myDictionary
                                                       options:0 // OR NSJSONWritingPrettyPrinted
                                                         error:&error];
    NSString *jsonString;
    if (! jsonData) {
        NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
        jsonString = @"{}";
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }


NSJSONWritingPrettyPrinted是可读性的字符串,0则不换行的格式
首先新建一个基于Sigle view Application的项目,名为GestureTest;我的项目结构如下:

往viewController.xib文件里拖动一个imageView,并使覆盖整个屏幕,改动属性为:

viewController.h文件:



     #import <UIKit/UIKit.h>  
      
     @interface ViewController : UIViewController{  
         IBOutlet UIImageView *imageView;  
     }  
     @property (nonatomic,retain)IBOutlet UIImageView *imageView;  
     @end

并使xib文件里的imageView与之连接;

然后是viewController.m文件的实现部分:



     @synthesize imageView;  
      
     CGFloat lastScaleFactor=1;//放大、缩小  
     CGFloat  netRotation;//旋转  
     CGPoint netTranslation;//平衡  
     NSArray *images;//图片数组  
     int imageIndex=0;//数组下标  
      
     - (void)viewDidLoad  
   {  
       //1、创建手势实例,并连接方法handleTapGesture,点击手势  
       UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGesture:)];  
       //设置手势点击数,双击:点2下  
       tapGesture.numberOfTapsRequired=2;  
       // imageView添加手势识别  
       [imageView addGestureRecognizer:tapGesture];  
       //释放内存  
       [tapGesture release];  
        
       //2、手势为捏的姿势:按住option按钮配合鼠标来做这个动作在虚拟器上  
       UIPinchGestureRecognizer *pinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinchGesture:)];  
       [imageView addGestureRecognizer:pinchGesture];//imageView添加手势识别  
       [pinchGesture release];  
        
       //3、旋转手势:按住option按钮配合鼠标来做这个动作在虚拟器上  
       UIRotationGestureRecognizer *rotateGesture=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(handleRotateGesture:)];  
       [imageView addGestureRecognizer:rotateGesture];  
       [rotateGesture release];  
        
       //4、拖手势  
       UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];  
      // [imageView addGestureRecognizer:panGesture];  
       [panGesture release];  
        
       //5、划动手势  
       images=[[NSArray alloc]initWithObjects:@"cell.jpg",@"heihua.jpg",@"xuanyi.jpg", nil];  
       //右划  
       UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGesture:)];  
       [imageView addGestureRecognizer:swipeGesture];  
       [swipeGesture release];  
       //左划  
       UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGesture:)];  
       swipeGesture.direction=UISwipeGestureRecognizerDirectionLeft;//不设置黑夜是右  
       [imageView addGestureRecognizer:swipeLeftGesture];  
       [swipeLeftGesture release];  
        
       //6、长按手势  
       UILongPressGestureRecognizer *longpressGesutre=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongpressGesture:)];  
       //长按时间为1秒  
       longpressGesutre.minimumPressDuration=1;  
       //允许15秒中运动  
       longpressGesutre.allowableMovement=15;  
       //所需触摸1次  
       longpressGesutre.numberOfTouchesRequired=1;  
       [imageView addGestureRecognizer:longpressGesutre];  
       [longpressGesutre release];  
        
       [super viewDidLoad];  
       // Do any additional setup after loading the view, typically from a nib.  
   }  
   //双击屏幕时会调用此方法,放大和缩小图片  
   -(IBAction)handleTapGesture:(UIGestureRecognizer*)sender{  
       //判断imageView的内容模式是否是UIViewContentModeScaleAspectFit,该模式是原比例,按照图片原时比例显示大小  
       if(sender.view.contentMode==UIViewContentModeScaleAspectFit){  
           //把imageView模式改成UIViewContentModeCenter,按照图片原先的大小显示中心的一部分在imageView  
           sender.view.contentMode=UIViewContentModeCenter;  
       }else{  
           sender.view.contentMode=UIViewContentModeScaleAspectFit;  
       }  
   }  
   //捏的手势,使图片放大和缩小,捏的动作是一个连续的动作  
   -(IBAction)handlePinchGesture:(UIGestureRecognizer*)sender{  
       //得到sender捏手势的大小  
       CGFloat factor=[(UIPinchGestureRecognizer*)sender scale];  
       if(factor>1){  
           //图片放大  
           sender.view.transform=CGAffineTransformMakeScale(lastScaleFactor+(factor-1), (lastScaleFactor+(factor-1)));  
                                                              
       }else{  
           //缩小  
           sender.view.transform=CGAffineTransformMakeScale(lastScaleFactor*factor, lastScaleFactor*factor);  
                                                              
       }  
       //状态是否结束,如果结束保存数据  
       if(sender.state==UIGestureRecognizerStateEnded){  
           if(factor>1){  
               lastScaleFactor+=(factor-1);  
           }else{  
               lastScaleFactor*=factor;  
           }  
       }  
   }  
   //旋转手势  
   -(IBAction)handleRotateGesture:(UIGestureRecognizer*)sender{  
       //浮点类型,得到sender的旋转度数  
       CGFloat rotation=[(UIRotationGestureRecognizer*)sender rotation];  
       //旋转角度CGAffineTransformMakeRotation  
       CGAffineTransform transform=CGAffineTransformMakeRotation(rotation+netRotation);  
       //改变图像角度  
      sender.view.transform=transform;  
      //状态结束,保存数据  
      if(sender.state==UIGestureRecognizerStateEnded){  
          netRotation+=rotation;  
      }  
        
  }  
  //拖手势  
  -(IBAction)handlePanGesture:(UIGestureRecognizer*)sender{  
      //得到拖的过程中的xy坐标  
      CGPoint translation=[(UIPanGestureRecognizer*)sender translationInView:imageView];  
      //平移图片CGAffineTransformMakeTranslation  
      sender.view.transform=CGAffineTransformMakeTranslation(netTranslation.x+translation.x, netTranslation.y+translation.y);  
      //状态结束,保存数据  
      if(sender.state==UIGestureRecognizerStateEnded){  
          netTranslation.x+=translation.x;  
          netTranslation.y+=translation.y;  
      }  
        
  }  
  //划动手势  
  -(IBAction)handleSwipeGesture:(UIGestureRecognizer*)sender{  
      //划动的方向  
      UISwipeGestureRecognizerDirection direction=[(UISwipeGestureRecognizer*) sender direction];  
      //判断是上下左右  
      switch (direction) {  
          case UISwipeGestureRecognizerDirectionUp:  
              NSLog(@"up");  
              break;  
          case UISwipeGestureRecognizerDirectionDown:  
              NSLog(@"down");  
              break;  
          case UISwipeGestureRecognizerDirectionLeft:  
              NSLog(@"left");  
              imageIndex++;//下标++  
              break;  
          case UISwipeGestureRecognizerDirectionRight:  
              NSLog(@"right");  
              imageIndex--;//下标--  
              break;  
          default:  
              break;  
      }  
      //得到不越界不<0的下标  
      imageIndex=(imageIndex<0)?([images count]-1):imageIndex%[images count];  
      //imageView显示图片  
      imageView.image=[UIImage imageNamed:[images objectAtIndex:imageIndex]];  
        
  }  
  //长按手势  
  -(IBAction)handleLongpressGesture:(UIGestureRecognizer*)sender{  
      //创建警告  
      UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"Image options" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Save Image",@"Copy", nil];  
      //当前view显示警告  
      [actionSheet showInView:self.view];  
      [actionSheet release];  
  }  
  -(void)dealloc{  
      [images release];  
      [imageView release];  
      [super dealloc];  
  }  


摘自:http://blog.csdn.net/chang6520/article/details/7924313
分页: 7/361 第一页 上页 2 3 4 5 6 7 8 9 10 11 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐