| 1 | <?php
|
|---|
| 2 | include 'wp-load.php';
|
|---|
| 3 |
|
|---|
| 4 | function wp_slash_1( $value ) {
|
|---|
| 5 | if ( is_array( $value ) ) {
|
|---|
| 6 | foreach ( $value as $k => $v ) {
|
|---|
| 7 | if ( is_array( $v ) ) {
|
|---|
| 8 | $value[$k] = wp_slash_1( $v );
|
|---|
| 9 | } else {
|
|---|
| 10 | $value[$k] = addslashes( $v );
|
|---|
| 11 | }
|
|---|
| 12 | }
|
|---|
| 13 | } else {
|
|---|
| 14 | $value = addslashes( $value );
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | return $value;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | function wp_slash_2( $value ) {
|
|---|
| 21 | if ( is_array( $value ) ) {
|
|---|
| 22 | $value = array_map( 'wp_slash_2', $value );
|
|---|
| 23 | } else {
|
|---|
| 24 | $value = addslashes( $value );
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | return $value;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | $simple_array = array(
|
|---|
| 31 | 'a' => "I can't see, isn't that it?",
|
|---|
| 32 | 'b' => "I can't see, isn't that it?",
|
|---|
| 33 | 'c' => "I can't see, isn't that it?",
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 | $nested_arrays = array(
|
|---|
| 37 | 'a' => array(
|
|---|
| 38 | 'a' => array(
|
|---|
| 39 | 'a' => "I can't see, isn't that it?",
|
|---|
| 40 | 'b' => "I can't see, isn't that it?",
|
|---|
| 41 | 'c' => "I can't see, isn't that it?",
|
|---|
| 42 | ),
|
|---|
| 43 | 'b' => "I can't see, isn't that it?",
|
|---|
| 44 | 'c' => "I can't see, isn't that it?",
|
|---|
| 45 | ),
|
|---|
| 46 | 'b' => "I can't see, isn't that it?",
|
|---|
| 47 | 'c' => "I can't see, isn't that it?",
|
|---|
| 48 | );
|
|---|
| 49 |
|
|---|
| 50 | foreach ( array( $simple_array, $nested_arrays ) as $array ) {
|
|---|
| 51 |
|
|---|
| 52 | timer_start();
|
|---|
| 53 |
|
|---|
| 54 | for ( $i = 0; $i < 1000000; $i++ ) {
|
|---|
| 55 | wp_slash_1( $array );
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | printf( "%s seconds.\n", timer_stop( 0, 3 ) );
|
|---|
| 59 |
|
|---|
| 60 | timer_start();
|
|---|
| 61 |
|
|---|
| 62 | for ( $i = 0; $i < 1000000; $i++ ) {
|
|---|
| 63 | wp_slash_2( $array );
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | printf( "%s seconds.\n", timer_stop( 0, 3 ) );
|
|---|
| 67 | }
|
|---|