文本字符串的内容分离

发布于 2024-11-02 17:19:27 字数 246 浏览 2 评论 0原文

我将这个 "&params=&offer=art-by-jeremy-johnson" 存储在我的数据库中。

是否有任何函数/方法可以使用上述内容作为输入值来获取 "Art by Jeremy Johnson" 的输出。应该仅在运行时将其更改为输出“Art by Jeremy Johnson”

这可以在 PHP 中完成吗?

请帮忙。

I have this "¶ms=&offer=art-by-jeremy-johnson" stored in my data base.

Is there any function / method to get the output as "Art by Jeremy Johnson" using the above as the input value. this should be changed to the output "Art by Jeremy Johnson" only on the runtime.

can this be done in PHP.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╰◇生如夏花灿烂 2024-11-09 17:19:27
$orig = '¶ms=&offer=art-by-jeremy-johnson';
$parts = explode('=', $orig);
$output = explode('-', end($parts));
echo ucwords(implode(' ', $output));
$orig = '¶ms=&offer=art-by-jeremy-johnson';
$parts = explode('=', $orig);
$output = explode('-', end($parts));
echo ucwords(implode(' ', $output));
春花秋月 2024-11-09 17:19:27

在Java中,我想你可以使用lastIndexOf来获取等号的最后一个索引,并获取字符串的其余部分(使用substring)。

if (myString.lastIndexOf("=") != -1) {
   String words = myString.substring(myString.lastIndexOf("=")+1);
   words.replaceAll("-", " ");
   return words;
}

In Java, I guess you can just use lastIndexOf to get the last index of the equals sign, and get the remainder of the string (using substring).

if (myString.lastIndexOf("=") != -1) {
   String words = myString.substring(myString.lastIndexOf("=")+1);
   words.replaceAll("-", " ");
   return words;
}
淡淡绿茶香 2024-11-09 17:19:27
$string="¶ms=&offer=art-by-jeremy-johnson";

parse_str($string,$output);
//print_r($output);
$str=ucwords(str_replace("-"," ",$output['offer']));
$string="¶ms=&offer=art-by-jeremy-johnson";

parse_str($string,$output);
//print_r($output);
$str=ucwords(str_replace("-"," ",$output['offer']));
零度° 2024-11-09 17:19:27

如果我理解得很好,你不想将某些单词大写。

这是一种方法:

$str = "¶ms=&offer=art-by-jeremy-johnson";

// List of words to NOT capitalized
$keep_lower = array('by');

parse_str($str, $p);
$o = explode('-', $p['offer']);
$r = array();
foreach ($o as $w) {
    if (!in_array($w, $keep_lower))
        $w = ucfirst($w);
    $r[] = $w;
}
$offer = implode(' ', $r);
echo $offer,"\n";

输出:

Art by Jeremy Johnson

If I understand well you want to not capitalized some words.

Here is a way to do it :

$str = "¶ms=&offer=art-by-jeremy-johnson";

// List of words to NOT capitalized
$keep_lower = array('by');

parse_str($str, $p);
$o = explode('-', $p['offer']);
$r = array();
foreach ($o as $w) {
    if (!in_array($w, $keep_lower))
        $w = ucfirst($w);
    $r[] = $w;
}
$offer = implode(' ', $r);
echo $offer,"\n";

output:

Art by Jeremy Johnson
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文