1

我有工作搜索页面,它显示所有工作的前 150 个字符来自 jobdescription:

{$listing.JobDescription|strip_tags|truncate:150} in smarty php template file

将返回:

Responsibilities:  1) Handle...  

这就是上面的源代码:http: //jsfiddle.net/e2ScF/126/

从编辑器和示例文本构建的原始文本位于:http: //jsfiddle.net/e2ScF/125/

我的问题是如何在没有 < p >、< br/> 和其他 html 标签的情况下显示求职结果,例如:

Responsibilities:1) Handle outbound telesales campaigns for consumer markets (for CallMark clients) by...
4

2 回答 2

1

这是一个 PHP 示例(请参阅实际操作):

<?php
    $string = '<p>
    &nbsp;</p>
<table align="center" border="0" cellpadding="3" cellspacing="0" class="normalword" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: rgb(0, 0, 0);" width="95%">
    <tbody>
        <tr>
            <td>
                <table align="center" border="0" bordercolor="#666666" cellpadding="3" cellspacing="0" class="normalword" width="100%">
                    <tbody>
                        <tr>
                            <td>
                                <div align="justify">
                                    Responsibilities:&nbsp;<br />
                                    <br />
                                    1) Handle outbound telesales campaigns for consumer markets (for CallMark clients) by utilizing effective presentation and creating positive relationship for all customer contacts with the aim to cross/up selling client&rsquo;s product and services.&nbsp;<br />
';

function firstXChars($string, $chars = 100)
{
    $string = trim(strip_tags($string));
    $string = str_replace(array("\n", "\r"), '', $string);
    preg_match('/^.{0,' . $chars. '}(?:.*?)\b/iu', $string, $matches);
    return $matches[0];
}

echo firstXChars($string);
于 2013-02-06T12:55:21.737 回答
1

您的问题是文本中间有很多空格,因此 truncate 将它们计入 150 个限制。

尝试使用 条带

{$listing.JobDescription|strip_tags|strip|truncate:150}
于 2013-02-06T19:24:00.353 回答