[英]combine two functions in php echo
i need to combine these two functions 我需要结合这两个功能
<meta name="twitter:image" value="<?php echo(str_replace("367.jpg", "150.jpg", $imageSrc)) ?>" /
and
<meta name="twitter:image"value="<?= substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4) ?>" />
i have tried this 我已经试过了
<meta name="twitter:image" value="<?php echo(str_replace("367.jpg", "150.jpg", $imageSrc)),substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4)?>" /
while the code has no issues but it renders this 虽然代码没有问题,但它呈现了这一点
<meta name="twitter:image" value="https://rlv.zcache.com/seal_of_success_blue_graduation_announcement-r6c3587ec36fd4246afd2add46333186a_6gdu5_150.jpg?rlvnet=1&bg=0xFFFFFFhttps://rlv.zcache.com/seal_of_success_blue_graduation_announcement-r6c3587ec36fd4246afd2add46333186a_6gdu5_367.jpg" /
whereas i want it to return just one url this 而我希望它只返回一个网址
https://rlv.zcache.com/seal_of_success_blue_graduation_announcement-r6c3587ec36fd4246afd2add46333186a_6gdu5_150.jpg
that is replace 367.jpg to 150.jpg and remove everything after.jpg ?rlvnet=1&bg=0xFFFFFF 即将367.jpg替换为150.jpg,然后删除所有内容。jpg ?rlvnet = 1&bg = 0xFFFFFF
Well, try 我们会尽力
For example, I'll take $imageSrc = "http://example.com/img_367.jpg?something"
例如,我将使用
$imageSrc = "http://example.com/img_367.jpg?something"
To be clear, you want first of all remove everything after the ?, an then replace 367 by 150. So try this : 需要明确的是,您首先要删除?之后的所有内容,然后将367替换为150。因此,请尝试以下操作:
<?= str_replace("367", "150", strstr($imageSrc, "?", true)) ?>
Call one function inside another and it will work: 在另一个函数中调用一个函数,它将起作用:
<meta name="twitter:image" value="<?=
str_replace(
"367.jpg",
"150.jpg",
substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4)
)
?>" />
Or do it step-by-step saving to the variable: 或逐步保存到变量中:
# remove tail
$imageSrc = substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4);
# replace size
$imageSrc = str_replace("367.jpg", "150.jpg", $imageSrc)
<meta name="twitter:image" value="<?= $imageSrc ?>" />
请尝试这个
<?php echo str_replace('_367.jpg','_150.jpg',current(explode("?",$imageSrc))); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.