{"id":31241636,"url":"https://github.com/arraypress/wp-string-utils","last_synced_at":"2025-09-23T00:12:16.759Z","repository":{"id":312870283,"uuid":"1015607542","full_name":"arraypress/wp-string-utils","owner":"arraypress","description":"Essential string manipulation utilities for WordPress development.","archived":false,"fork":false,"pushed_at":"2025-07-07T20:39:40.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-02T15:14:23.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-07T18:59:26.000Z","updated_at":"2025-08-26T18:17:19.000Z","dependencies_parsed_at":"2025-09-02T15:14:34.633Z","dependency_job_id":"b31679a3-287b-4a06-8a8b-fd83e7e04dbf","html_url":"https://github.com/arraypress/wp-string-utils","commit_stats":null,"previous_names":["arraypress/wp-string-utils"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/wp-string-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-string-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-string-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-string-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-string-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/wp-string-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-string-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276493472,"owners_count":25652188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-23T00:12:14.097Z","updated_at":"2025-09-23T00:12:16.740Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# WordPress String Utilities\n\nEssential string manipulation utilities for WordPress development. Provides powerful methods for string checking, validation, manipulation, and content processing that WordPress doesn't offer out of the box.\n\n## Features\n\n* 🎯 **Comprehensive API**: 42 focused methods for common string operations\n* 🔍 **Enhanced Checking**: Multi-needle contains, starts/ends with arrays, pattern matching\n* ✅ **Built-in Validation**: Email, URL, date, numeric, and format validation\n* 🔧 **Smart Manipulation**: First/last replace, content extraction, whitespace handling\n* 📝 **Content Processing**: Reading time, word limits, excerpts with WordPress integration\n* 🎨 **Case Conversion**: camelCase, snake_case, kebab-case, and more\n* 🛡️ **WordPress-Native**: Uses WordPress functions like `wp_strip_all_tags()`, `is_email()`\n\n## Requirements\n\n* PHP 7.4 or later\n* WordPress 5.0 or later\n\n## Installation\n\n```bash\ncomposer require arraypress/wp-string-utils\n```\n\n## Basic Usage\n\n### String Checking\n\n```php\nuse ArrayPress\\StringUtils\\Str;\n\n// Check for multiple needles\nStr::contains_any( 'admin-dashboard.php', 'admin', 'dashboard' );  // true\nStr::contains_all( 'WordPress Plugin', 'Word', 'Press' );          // true\n\n// Enhanced starts/ends checking\nStr::starts_with( 'image.jpg', ['.jpg', '.png', '.gif'] );        // false\nStr::ends_with( 'image.jpg', ['.jpg', '.png', '.gif'] );          // true\n\n// Pattern matching with wildcards\nStr::matches_any( 'admin.php', ['admin.*', 'edit.*'], true );     // true\n```\n\n### String Validation\n\n```php\n// Format validation\nStr::is_email( 'user@example.com' );      // true\nStr::is_url( 'https://example.com' );     // true\nStr::is_date( '2024-01-15' );             // true\nStr::is_ip( '192.168.1.1' );             // true\n\n// Type checking\nStr::is_numeric( '123.45' );              // true\nStr::is_integer( '123' );                 // true\nStr::is_float( '123.45' );                // true\nStr::is_json( '{\"key\":\"value\"}' );        // true\n\n// Character validation\nStr::is_alpha( 'HelloWorld' );            // true\nStr::is_alphanumeric( 'Hello123' );       // true\nStr::is_hex( 'FF0000' );                  // true\nStr::is_blank( '   ' );                   // true\n```\n\n### String Manipulation\n\n```php\n// Advanced replacement\nStr::replace_first( 'hello', 'hi', 'hello world hello' );    // 'hi world hello'\nStr::replace_last( 'hello', 'hi', 'hello world hello' );     // 'hello world hi'\n\n// Content extraction\nStr::between( '[', ']', 'Hello [world] test' );              // 'world'\nStr::between( '\u003cp\u003e', '\u003c/p\u003e', '\u003cp\u003eContent\u003c/p\u003e' );             // 'Content'\n\n// Smart truncation\nStr::truncate( 'This is a long sentence', 10 );              // 'This is...'\nStr::words( 'The quick brown fox jumps', 3 );                // 'The quick brown...'\n\n// Whitespace handling\nStr::reduce_whitespace( '  hello    world  ' );              // 'hello world'\nStr::remove_whitespace( 'hello world' );                     // 'helloworld'\nStr::remove_line_breaks( \"line1\\nline2\" );                   // 'line1line2'\n```\n\n### Case Conversion\n\n```php\n// Modern case formats\nStr::camel( 'hello-world' );              // 'helloWorld'\nStr::snake( 'HelloWorld' );               // 'hello_world'  \nStr::kebab( 'Hello World' );              // 'hello-world'\nStr::title( 'hello world' );              // 'Hello World'\n\n// Basic case conversion (accepts any type)\nStr::upper( ['a', 'b'] );                 // '[\"A\",\"B\"]'\nStr::lower( 'HELLO' );                    // 'hello'\nStr::sentence( 'HELLO WORLD' );           // 'Hello world'\n```\n\n### Content Processing\n\n```php\n// WordPress-optimized content handling\nStr::excerpt( '\u003cp\u003eLong content here...\u003c/p\u003e', 50 );           // 'Long content here...'\nStr::word_count( '\u003cp\u003eHello \u003cstrong\u003eworld\u003c/strong\u003e\u003c/p\u003e' );    // 2\nStr::reading_time( $post_content );                          // ['minutes' =\u003e 3, 'seconds' =\u003e 45]\n\n// Content splitting\nStr::to_words( 'hello world test' );                         // ['hello', 'world', 'test']\nStr::to_lines( \"line1\\nline2\\nline3\" );                      // ['line1', 'line2', 'line3']\nStr::to_sentences( 'Hello world. How are you?' );            // ['Hello world', ' How are you']\n```\n\n### Utility Operations\n\n```php\n// Safe conversion\nStr::from( ['a', 'b'] );                  // '[\"a\",\"b\"]'\nStr::from( 123 );                         // '123'\n\n// Array conversion\nStr::to_array( 'apple, banana, cherry' ); // ['apple', 'banana', 'cherry']\nStr::to_csv( ['red', 'green', 'blue'] );  // 'red,green,blue'\n\n// Text processing\nStr::ascii( 'café naïve' );               // 'cafe naive'\nStr::normalize( '  HELLO World  ' );      // 'hello world'\n```\n\n## API Reference\n\n### String Checking Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `contains_any($haystack, ...$needles)` | Check if string contains any needle | `bool` |\n| `contains_all($haystack, ...$needles)` | Check if string contains all needles | `bool` |\n| `starts_with($haystack, $needles)` | Check if starts with needle(s) | `bool` |\n| `ends_with($haystack, $needles)` | Check if ends with needle(s) | `bool` |\n| `matches_any($needle, $patterns, $wildcard)` | Pattern matching with wildcards | `bool` |\n\n### Validation Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `is_json($string)` | Check if valid JSON | `bool` |\n| `is_email($string)` | Check if valid email | `bool` |\n| `is_url($string)` | Check if valid URL | `bool` |\n| `is_date($string)` | Check if valid date | `bool` |\n| `is_ip($string)` | Check if valid IP address | `bool` |\n| `is_numeric($string)` | Check if numeric | `bool` |\n| `is_integer($string)` | Check if integer | `bool` |\n| `is_float($string)` | Check if float | `bool` |\n| `is_alpha($string)` | Check if alphabetic only | `bool` |\n| `is_alphanumeric($string)` | Check if alphanumeric only | `bool` |\n| `is_hex($string)` | Check if hexadecimal | `bool` |\n| `is_blank($string)` | Check if empty/whitespace | `bool` |\n| `is_length_valid($string, $min, $max)` | Check length within range | `bool` |\n\n### Manipulation Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `replace_first($search, $replace, $subject)` | Replace first occurrence | `string` |\n| `replace_last($search, $replace, $subject)` | Replace last occurrence | `string` |\n| `between($start, $end, $subject)` | Extract content between delimiters | `string` |\n| `truncate($string, $length, $suffix)` | Truncate with suffix | `string` |\n| `words($string, $limit, $suffix)` | Limit word count | `string` |\n| `reduce_whitespace($string)` | Reduce multiple spaces to single | `string` |\n| `remove_whitespace($string)` | Remove all whitespace | `string` |\n| `remove_line_breaks($string)` | Remove line breaks | `string` |\n\n### Case Conversion Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `camel($string)` | Convert to camelCase | `string` |\n| `snake($string)` | Convert to snake_case | `string` |\n| `kebab($string)` | Convert to kebab-case | `string` |\n| `title($string)` | Convert to Title Case | `string` |\n| `upper($value)` | Convert to UPPERCASE | `string` |\n| `lower($value)` | Convert to lowercase | `string` |\n| `sentence($value)` | Convert to Sentence case | `string` |\n\n### Content Processing Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `excerpt($content, $length, $stripTags)` | Create safe excerpt | `string` |\n| `reading_time($content, $wpm)` | Estimate reading time | `array` |\n| `word_count($string)` | Count words (strips HTML) | `int` |\n\n### Utility Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| `from($value)` | Convert value to string safely | `string` |\n| `ascii($string)` | Remove accents, convert to ASCII | `string` |\n| `normalize($string)` | Trim and lowercase | `string` |\n| `to_array($string, $separator)` | Convert CSV string to array | `array` |\n| `to_csv($array, $separator)` | Convert array to CSV string | `string` |\n| `to_words($string)` | Split into words array | `array` |\n| `to_lines($string)` | Split into lines array | `array` |\n| `to_sentences($string)` | Split into sentences array | `array` |\n\n## Common Use Cases\n\n### Form Validation\n\n```php\n// Validate user input\n$email_valid = Str::is_email( $_POST['email'] );\n$phone_valid = Str::is_numeric( $_POST['phone'] );\n$website_valid = Str::is_url( $_POST['website'] );\n$birthdate_valid = Str::is_date( $_POST['birthdate'] );\n\n// Check required fields\n$name_provided = !Str::is_blank( $_POST['name'] );\n$message_length = Str::is_length_valid( $_POST['message'], 10, 500 );\n```\n\n### Content Processing\n\n```php\n// Create clean excerpts\n$excerpt = Str::excerpt( $post_content, 150 );\n\n// Process user content\n$clean_title = Str::title( $user_input );\n$slug = Str::kebab( $clean_title );\n$normalized = Str::normalize( $user_search );\n\n// Content analysis\n$reading_time = Str::reading_time( $article_content );\n$word_count = Str::word_count( $content );\n```\n\n### Data Cleanup\n\n```php\n// Clean messy data\n$clean_text = Str::reduce_whitespace( $messy_input );\n$single_line = Str::remove_line_breaks( $multi_line_text );\n$no_accents = Str::ascii( $international_text );\n\n// Parse structured data\n$tags = Str::to_array( $comma_separated_tags );\n$csv_export = Str::to_csv( $tag_array );\n```\n\n### WordPress Integration\n\n```php\n// Meta field processing\n$featured = Str::is_json( $meta_value ) ? json_decode( $meta_value ) : $meta_value;\n$categories = Str::to_array( get_post_meta( $post_id, 'categories', true ) );\n\n// Admin interface\n$admin_pages = ['admin.php', 'edit.php', 'options.php'];\n$is_admin_page = Str::ends_with( $current_page, $admin_pages );\n\n// Content filtering\n$safe_excerpt = Str::excerpt( get_the_content(), 200 );\n$estimated_time = Str::reading_time( get_the_content() );\n```\n\n## Key Benefits\n\n- **Fills WordPress Gaps**: Provides methods WordPress doesn't offer\n- **Enhanced Functionality**: Better versions of basic PHP string functions\n- **WordPress-Optimized**: Integrates with WordPress functions and conventions\n- **Type Safety**: Strict typing with predictable return values\n- **Performance-Focused**: Efficient implementations without heavy dependencies\n- **Developer-Friendly**: Intuitive method names and consistent API\n\n## Requirements\n\n- PHP 7.4+\n- WordPress 5.0+\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL-2.0-or-later License.\n\n## Support\n\n- [Documentation](https://github.com/arraypress/wp-string-utils)\n- [Issue Tracker](https://github.com/arraypress/wp-string-utils/issues)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-string-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fwp-string-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-string-utils/lists"}