TestRegex.php 852 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/5/19
  6. * Time: 下午2:00
  7. */
  8. class TestRegex extends PHPUnit_Framework_TestCase
  9. {
  10. public function testReserved()
  11. {
  12. $t = base64_encode('5');
  13. $regxp = '/([^=#]+=[^#]*)[#]?/i';
  14. $src='top=1#stars=3#desc=你好世界';
  15. $val = preg_match_all($regxp,$src,$match);
  16. if($val == false) return false;
  17. $result = [];
  18. if(count($match) == 2)
  19. {
  20. foreach($match[1] as $val)
  21. {
  22. $kv = preg_split('/=/',$val);
  23. if(!empty($kv))
  24. {
  25. $k = trim($kv[0]);
  26. $v = trim($kv[1]);
  27. if(!empty($k)) {
  28. $result[$k] = $v;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }