{"id":18656240,"url":"https://github.com/bayfrontmedia/php-sanitize","last_synced_at":"2025-04-11T17:32:09.559Z","repository":{"id":62492272,"uuid":"282992508","full_name":"bayfrontmedia/php-sanitize","owner":"bayfrontmedia","description":"Simple class used to sanitize, filter and cast data.","archived":false,"fork":false,"pushed_at":"2024-12-23T20:26:24.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T16:51:29.374Z","etag":null,"topics":["cast","escape","filter","php","sanitize","xss"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bayfrontmedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null}},"created_at":"2020-07-27T19:13:36.000Z","updated_at":"2024-12-23T20:26:04.000Z","dependencies_parsed_at":"2023-02-14T19:46:36.866Z","dependency_job_id":null,"html_url":"https://github.com/bayfrontmedia/php-sanitize","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-sanitize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-sanitize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-sanitize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-sanitize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayfrontmedia","download_url":"https://codeload.github.com/bayfrontmedia/php-sanitize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449896,"owners_count":21105582,"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","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":["cast","escape","filter","php","sanitize","xss"],"created_at":"2024-11-07T07:22:29.238Z","updated_at":"2025-04-11T17:32:09.544Z","avatar_url":"https://github.com/bayfrontmedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PHP sanitize\n\nSimple class used to sanitize, filter and cast data.\n\n- [License](#license)\n- [Author](#author)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Author\n\n\u003cimg src=\"https://cdn1.onbayfront.com/bfm/brand/bfm-logo.svg\" alt=\"Bayfront Media\" width=\"250\" /\u003e\n\n- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github\u0026amp;utm_medium=direct)\n- [Bayfront Media GitHub](https://github.com/bayfrontmedia)\n\n## Requirements\n\n* PHP `^8.0` (Tested up to `8.4`)\n\n## Installation\n\n```\ncomposer require bayfrontmedia/php-sanitize\n```\n\n## Usage\n\n- [cast](#cast)\n- [email](#email)\n- [url](#url)\n- [path](#path)\n- [escape](#escape)\n\n\u003chr /\u003e\n\n### cast\n\n**Description:**\n\nEnsures a given variable will be returned as a specific type. Defaults to \"string\".\n\n**Parameters:**\n\n- `$var` (mixed)\n- `$type = self::CAST_STRING` (string): Any `CAST_*` constant\n\nValid cast types are available as the following constants:\n\n- `CAST_ARRAY`: array\n- `CAST_BOOL`: bool\n- `CAST_FLOAT`: float\n- `CAST_INT`: int\n- `CAST_OBJECT`: object\n- `CAST_STRING`: string\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\Sanitize\\Sanitize;\n\n$input = '1.42';\n\necho Sanitize::cast($input, Sanitize::CAST_FLOAT);\n\n```\n\n\u003chr /\u003e\n\n### email\n\n**Description:**\n\nFilters string for valid email characters.\n\n**Parameters:**\n\n- `$email` (string)\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\Sanitize\\Sanitize;\n\necho Sanitize::email('email@example.com');\n```\n\n\u003chr /\u003e\n\n### url\n\n**Description:**\n\nFilters string for valid URL characters.\n\n**Parameters:**\n\n- `$url` (string)\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\Sanitize\\Sanitize;\n\necho Sanitize::url('https://www.example.com);\n```\n\n\u003chr /\u003e\n\n### path\n\n**Description:**\n\nFilters string for valid path syntax, with optional trailing slash.\n\nThis method removes any whitespace, spaces, and leading slashes. It will also convert reverse and multiple slashes to one single forward slash.\n\n**Parameters:**\n\n- `$path` (string)\n- `$trailing = true` (bool): Require trailing slash\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\Sanitize\\Sanitize;\n\n$path = '/some/ bad//path';\n\necho Sanitize::path($path);\n\n```\n\n\u003chr /\u003e\n\n### escape\n\n**Description:**\n\nEscape strings and arrays. Other data types return their original value.\n\n**NOTE:** Use caution when escaping entire arrays, as strings should typically only be escaped when outputting to HTML.\n\nSee: [https://www.php.net/manual/en/mbstring.supported-encodings.php](https://www.php.net/manual/en/mbstring.supported-encodings.php)\n\n**Parameters:**\n\n- `$value` (mixed)\n- `$encoding = 'UTF-8'` (string)\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\Sanitize\\Sanitize;\n\n$html = '\u003ca href=\"#\"\u003eHyperlink\u003c/a\u003e';\n\necho Sanitize::escape($html);\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-sanitize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayfrontmedia%2Fphp-sanitize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-sanitize/lists"}