PHP:如何插入a<;br/>-在电子邮件地址内的@后面添加标记

PHP:如何插入a<;br/>-在电子邮件地址内的@后面添加标记,php,Php,我有一些电子邮件地址太长的问题。所以我想在@字符后设置一个中断 但不幸的是,@符号似乎是一个特殊字符。这就是为什么它不适用于: str_replace ('@' , '@<br/>' , $email); stru替换('@','@',$email); 有没有其他方法可以完成这项工作?我将尝试回答这个问题,因为您很可能没有向我们展示完整的代码 如果您有可能同时使用另一个函数,例如strlen(),那么这就可以解释它,以及您是如何使用它的 您也可能正在使用另一个功能,这在您发布时

我有一些电子邮件地址太长的问题。所以我想在
@
字符后设置一个中断

但不幸的是,
@
符号似乎是一个特殊字符。这就是为什么它不适用于:

str_replace ('@' , '@<br/>' , $email); 
stru替换('@','@
',$email);

有没有其他方法可以完成这项工作?

我将尝试回答这个问题,因为您很可能没有向我们展示完整的代码

如果您有可能同时使用另一个函数,例如
strlen()
,那么这就可以解释它,以及您是如何使用它的

您也可能正在使用另一个功能,这在您发布时是未知的。因此,如果我的答复不能为你提供解决办法,你将需要详细说明这一点

  • 就我而言,您的“发布”代码已签出,所以我看不出怎么会失败
使用以下代码并结合您发布的代码,证明是成功的

<?php 
// email with 33 characters
$email = "emailwith33characters@example.com";

// if more or equal to 33 characters
if(strlen($email) >= 33){
    echo "The email <b>$email</b> contains 33 or more characters. ";
    echo "Now putting them into 2 lines...";

    echo "<br>";

// echo str_replace('@', '@<br/>', $email);
    echo "First line: " . str_replace('@', '@<br/>Second line: ', $email);
}

else{
    echo "Email is within character limit.";
}

谢谢您的帮助。不幸的是,“str_replace”不能与代码中的“@”字符一起使用。如果我用“.”字符测试它,它有时会起作用。每次我在浏览器中重新加载页面时,“str_replace”结果都会更改

这里有更多的代码。它来自Wordpress插件,用于显示员工的联系方式。它在所有员工岗位上循环运行

        $i = 0;
    if( $staff->have_posts() ) {
        if ($headline =='yes') {
            $output .= '<h1 class="staff-group-mainheader">'.$maingroupname.'</h1>';
        }
        $output .= '<div class="staff-member-listing '.$group.'">';

        while( $staff->have_posts() ) : $staff->the_post();
            unset($staff_member_classes);

            $terms = get_the_terms( $post->id, 'staff-member-group' ); // get an array of all the terms as objects.

            $term_slug = array(); // save the slugs in an array
            $term_name = array(); // save the slugs in an array
            foreach( $terms as $term ) {
                $term_slug[] = $term->slug; // this grabs the hyphenated slug
                $term_name[] = $term->name; // this grabs the actual name
                $staff_member_classes .= ' '.$term->slug;
            }

        if ($i == ($staff->found_posts)-1) {
            $staff_member_classes .= " last";
        }

        if ($i % 2) {
            $oddorevenpost = 'even';
        } else {
            $oddorevenpost = 'odd';
        }

        if (($oddorevenpost == $oddoreven) || ($oddoreven == '')) {

            $output .= '<div class="staff-member '.$oddorevenpost.' '.$staff_member_classes.'">';

        global $post;

        $custom     = get_post_custom();
        $name       = get_the_title();
        $name_slug  = basename(get_permalink());
        $title      = $custom["_staff_member_title"][0];
        $function   = $custom["_staff_member_fb"][0];
        $email      = antispambot($custom["_staff_member_email"][0]);

        if (!empty($custom["_staff_member_phone"][0])) {
            $phone = '<li><i class="icons lycon-phone"></i><span class="staff-phone">'.$custom["_staff_member_phone"][0].'</span></li>';
        }
        if (!empty($custom["_staff_member_mobile"][0])) {
            $mobile = '<li><i class="icons icon-mobile-6"></i><span class="staff-mobile">'.$custom["_staff_member_mobile"][0].'</span></li>';
        }
        if (!empty($custom["_staff_member_fax"][0])) {
            $fax = '<li><i class="icons lycon-fax"></i><span class="staff-fax">'.$custom["_staff_member_fax"][0].'</span></li>';
        }
        $company    = $custom["_staff_member_company"][0];
        $street     = $custom["_staff_member_street"][0];
        $city       = $custom["_staff_member_city"][0];
        $country    = $custom["_staff_member_country"][0];
        $bio        = $custom["_staff_member_bio"][0];



        if(has_post_thumbnail()){

            $postidthumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
            $photo_url = wp_get_attachment_medium_url( $postidthumb );
            $photo = '<div class="staff-member-container" style="background: url('.$photo_url.') no-repeat right bottom;">';
        }else{
            $photo_url = '';
            $photo = '';
        }


        if (function_exists('wpautop')){
            $bio_format = '<div class="staff-member-bio">'.wpautop($bio).'</div>';
        }
        $emailbreak = str_replace ('@' , '@<br/>' , $email);

        $email_mailto = '<li><i class="icons icon-mail-7"></i><span class="staff-email"><a class="staff-member-email" href="mailto:'.$email.'" title="Email '.$name.'">'.$emailbreak.'</a></span></li>';
        $email_nolink = antispambot( $email );

        $accepted_single_tags = $default_tags;
        $replace_single_values = array($name, $name_slug, $photo_url, $title, $function, $email_nolink, $phone, $mobile, $fax, $company, $street, $city, $country, $bio, $fb_url, $tw_url);

        $accepted_formatted_tags = $default_formatted_tags;
        if ( $title =='') {
            $formattedname = '<h3 class="staff-member-name">'.$name.'</h3>';
        } else {
            $formattedname = '<h3 class="staff-member-name">'.$title.' '.$name.'</h3>';
        }
        $replace_formatted_values = array($formattedname, '<h4 class="staff-member-position">'.$title.'</h4>', $photo, $email_mailto, $bio_format );

        $loop_markup = str_replace($accepted_single_tags, $replace_single_values, $loop_markup);
        $loop_markup = str_replace($accepted_formatted_tags, $replace_formatted_values, $loop_markup);

        $output .= $loop_markup;

        $loop_markup = $loop_markup_reset;



        $output .= '</div> <!-- Close staff-member -->';
        }
        $i += 1;

        endwhile;

        $output .= "</div> <!-- Close staff-member-listing -->";
    }
}

wp_reset_query();

$output = $style_output.$output;
$i=0;
如果($staff->have_posts()){
如果($headline=='yes'){
$output.=''.$maingroupname'.';
}
$output.='';
而($staff->have_posts()):$staff->the_post();
unset(员工、成员、班级);
$terms=get_the_terms($post->id,'staff-member-group');//获取所有术语作为对象的数组。
$term_slug=array();//将slug保存在数组中
$term_name=array();//将slug保存在数组中
foreach($terms作为$term){
$term_slug[]=$term->slug;//这将获取带连字符的slug
$term_name[]=$term->name;//这将获取实际名称
$staff\u member\u classes.=''.$term->slug;
}
如果($i==($staff->found_posts)-1){
$staff\u member\u classes.=“last”;
}
如果($i%2){
$oddorevenpost=‘偶数’;
}否则{
$oddorevenpost='odd';
}
如果($oddorevenpost==$oddoreven)| |($oddoreven==''){
$output.='';
全球$员额;
$custom=get_post_custom();
$name=获取标题();
$name\u slug=basename(get\u permalink());
$title=$custom[“\u职员\u成员\u title”][0];
$function=$custom[“\u staff\u member\u fb”][0];
$email=antispambot($custom[“\u staff\u member\u email”][0]);
如果(!empty($custom[“\u staff\u member\u phone”][0])){
$phone='
  • 。$custom[“\u职员\u成员\u电话”][0]。
  • ”; } 如果(!empty($custom[“\u staff\u member\u mobile”][0])){ $mobile='
  • 。$custom[“\u staff\u member\u mobile”][0]。
  • ”; } 如果(!empty($custom[“\u staff\u member\u fax”][0])){ $fax='
  • 。$custom[“\u职员\u成员\u传真”][0]。
  • ”; } $company=$custom[“\u员工\成员\公司”][0]; $street=$custom[“_staff_member_street”][0]; $city=$custom[“\u职员\u成员\u城市”][0]; $country=$custom[“\u职员\成员\国家”][0]; $bio=$custom[“\u职员\成员\u bio”][0]; 如果(具有\u post\u缩略图()){ $postidthumb=wp_获取_附件_url(获取_发布_缩略图_id($post->id)); $photo\u url=wp\u get\u attachment\u medium\u url($postdtumb); $photo=''; }否则{ $photo_url=''; $photo=''; } 如果(函数_存在('wpautop')){ $bio_格式=“”.wpautop($bio)。“”; } $emailbreak=str_replace('@','@
    ',$email); $email_mailto='
  • '; $email\u nolink=antispambot($email); $accepted_single_tags=$default_tags; $replace_single_values=array($name、$name_slug、$photo_url、$title、$function、$email_nolink、$phone、$mobile、$fax、$company、$street、$city、$country、$bio、$fb_url、$tw_url); $accepted_formatted_tags=$default_formatted_tags; 如果($title=''){ $formattedname='.$name'; }否则{ $formattedname='.$title'.$name'.'; } $replace_formatted_values=array($formattedname,“.$title.”,$photo,$email_mailto,$bio_format); $loop\u markup=str\u replace($accepted\u single\u tags,$replace\u single\u values,$loop\u markup); $loop\u markup=str\u replace($accepted\u formatted\u tags,$replace\u formatted\u values,$loop\u markup); $output.=$loop\u标记; $loop\u markup=$loop\u markup\u reset; $output.=''; } $i+=1; 结束时; $output.=“”; } } wp_reset_query(); $output=$style_output.$output;
    请向我们展示您的完整真实代码。所示代码应按预期工作,只要您将其重新分配给变量,您的假设是错误的,这反过来使您的问题无法正常回答如果您想将其分成两部分,请使用
    explode('@',$email)
    按原样测试您的代码,它在两行上返回了
    asfasdfassfd@
    asdfdssf.com
    ,这是在HTML source
    asfasdfassfd@
    asdffassfd.com
    中,您两天前发布了您的问题并请求帮助,我收到了评论和答案。您需要在这里与我们合作,并发布您可能有的任何评论,包括您可能没有向我们展示的其他代码;请回答。