[英]replace string php with html mailto tag
我有一个来自用户输入的字符串电子邮件地址($ option ['footer_email']),我想用mailto html标签替换它。 到目前为止,我尝试了几种方法,并尝试使用str_replace(),但它没有成功。
$email = array($option['footer_email']);
$replace = array('<a href="mailto:$option['footer_email']">$option['footer_email']</a>');
echo str_replace($email, $replace, $option['footer_email']);
并返回语法错误,意外的'footer_email'(T_STRING),期待')'
我也尝试使用preg_replace(),但那个没有帮助。 我该如何解决这个问题?
尝试这个
$email = $option['footer_email'];
$replace = '<a href="mailto:'.$option['footer_email'].'">'.$option['footer_email'].'</a>';
echo str_replace($email, $replace, $option['footer_email']);
基本上你的变量不会被读取,因为它是字符串的一部分。
你为什么要做str_replace
? 为什么不这样做呢?
echo '<a href="mailto:'.$option['footer_email'].'">'.$option['footer_email'].'</a>';
请检查你的Apostrophe正确打开和关闭,这是一个虚拟值的工作示例
$option['footer_email'] = 'test@test.com';
$email = array($option['footer_email']);
$replace = array("<a href='mailto:$option[footer_email]'>$option[footer_email]</a>");
echo str_replace($email, $replace, $option['footer_email']);
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$email = array($option['footer_email']);
$replace = array('<a href="mailto:"' . $option['footer_email'] . '">' .$option['footer_email'] . '</a>');
echo str_replace($email, $replace, $option['footer_email']);
尝试这个
$option['footer_email']="waseem@waseem.com";
$email = array($option['footer_email']);
$replace = '<a href="mailto:'.$option['footer_email'].'">'.$option['footer_email'].'</a>';
$replace_val= str_replace($email, $replace, $option['footer_email']);
//check By var_dump
var_dump($replace_val);
//check By Print_r
print_r($replace_val);
//check By echo
echo $replace_val;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.