utf8_uri_encode example

// Preserve escaped octets.     $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title );
    // Remove percent signs that are not part of an octet.     $title = str_replace( '%', '', $title );
    // Restore octets.     $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title );

    if ( seems_utf8( $title ) ) {
        if ( function_exists( 'mb_strtolower' ) ) {
            $title = mb_strtolower( $title, 'UTF-8' );
        }
        $title = utf8_uri_encode( $title, 200 );
    }

    $title = strtolower( $title );

    if ( 'save' === $context ) {
        // Convert &nbsp, &ndash, and &mdash to hyphens.         $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
        // Convert &nbsp, &ndash, and &mdash HTML entities to hyphens.         $title = str_replace( array( ' ', ' ', '–', '–', '—', '—' ), '-', $title );
        // Convert forward slash to hyphen.         $title = str_replace( '/', '-', $title );

        

function _truncate_post_slug( $slug$length = 200 ) {
    if ( strlen( $slug ) > $length ) {
        $decoded_slug = urldecode( $slug );
        if ( $decoded_slug === $slug ) {
            $slug = substr( $slug, 0, $length );
        } else {
            $slug = utf8_uri_encode( $decoded_slug$length, true );
        }
    }

    return rtrim( $slug, '-' );
}

/** * Adds tags to a post. * * @see wp_set_post_tags() * * @since 2.3.0 * * @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post. * @param string|array $tags Optional. An array of tags to set for the post, or a string of tags * separated by commas. Default empty. * @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure. */
Home | Imprint | This part of the site doesn't use cookies.