dsilver / arjoin
一个简单的PHP字符串绑定/URL友好的slug包。它可以绕过表情符号、图标或字符符号,将它们转换为可访问的字符串格式。
1.0.0
2023-10-16 12:19 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10.4
README
Arjoin是一个简单的PHP字符串绑定/URL友好的slug包。它可以绕过表情符号、图标或字符符号,将它们转换为可访问的字符串格式。
目录
安装
要在PHP项目中使用Arjoin,您可以通过Composer安装它。确保您的项目中已安装Composer。如果您没有Composer,您可以从https://getcomposer.org/下载并安装它。
要安装Arjoin,您可以使用以下composer命令
composer require dsilver/arjoin
Arjoin将被自动下载并添加到您的项目中。
发布说明
版本 1.0.0
用法
Arjoin提供了一种简单的方法从字符串生成URL友好的slug。
<?php use Dsilver\Arjoin\joiner; // Use your package's classes and methods $output = joiner::select("This is a Sample String");
结果
this-is-a-sample-string
您可以将 "This is a Sample String" 替换为您自己的字符串以生成一个slug。
在laravel中测试
添加到您的app.blade.php中
{{ use Dsilver\Arjoin\joiner::select("This is a Sample String") }}
示例
domain-dot-com/articles/title
domain-dot-com/articles/The Benefits of Regular Exercise
示例:从数据库中获取的文章数据
$url_article = joiner::select($article.title);
结果
domain-dot-com/articles/the-benefits-of-regular-exercise
示例
$characters = "Thís-Ís å Spéciäl 😜Stríng! My heart❤️ #coding"; $sample = joiner::select($characters);
结果
th-s-s-sp-ci-l-str-ng-my-heart-coding
高级示例
<?php use Dsilver\Arjoin\joiner; // Create a Arjoin object with an initial string $chain =joiner::select("This is a Sample String"); // Perform some operations using the chainable methods $result = $chain ->uppercase() // Converts the string to uppercase ->replace("Sample", "Example") // Replaces "Sample" with "Example" ->truncate(10) // Truncates the string to 10 characters ->getValue(); // Gets the resulting string echo $result; // Output the result
<?php use Dsilver\Arjoin\joiner; // Create a Arjoin object with an initial string $chain =joiner::select("This is a Sample String"); // Perform operations using chainable methods and store the intermediate results $uppercaseResult = $chain->uppercase(); $replaceResult = $uppercaseResult->replace("Sample", "Example"); $truncateResult = $replaceResult->truncate(10); // Get the final result $finalString = $truncateResult->getValue(); // Output the results at each step echo "Original String: " . $chain->getValue() . "<br>"; echo "Uppercase Result: " . $uppercaseResult->getValue() . "<br>"; echo "Replace Result: " . $replaceResult->getValue() . "<br>"; echo "Truncate Result: " . $truncateResult->getValue() . "<br>"; echo "Final Result: " . $finalString;
贡献
如果您想为Arjoin的开发做出贡献,可以按照以下步骤操作
- 在GitHub上Fork Arjoin存储库。
- 将您的Forked存储库克隆到本地开发环境。
- 为您的功能或错误修复创建一个新分支。
- 实现您的更改。
- 如有必要,编写单元测试。
- 运行PHPUnit以确保您的代码通过测试。
- 提交您的更改并将它们推送到您的GitHub存储库。
- 向原始Arjoin存储库创建一个拉取请求(PR)。
请确保遵守我们的行为准则并遵循我们的贡献指南。
许可证
Arjoin受MIT许可证的许可。有关详细信息,请参阅LICENSE文件。