English 中文(简体)
说明目标制定后的案文
原标题:Substring a text since the target founded

我在我的营地网页上进行了搜索,现在正在ok。

在我的调查结果下,我强调了我内容的突出目标。

$search_tag_text = @preg_replace("/($mysearch)/i", "<u style="color:red">$1</u>", $row->txtContent);

奥基语,但是,在我的内容中找到了明确的目标之后,能否在20个字之前和20个字之后显示,而不是列出我的所有内容?

任何帮助都将受到赞赏。

问题回答

我想尝试的是:

$matches = array();
preg_match("/($mysearch)/i", $search_tag_text, $matches, PREG_OFFSET_CAPTURE);

之后,在座各位将被发现的扼杀物所抵消的情况下,你可以做到:

$search_tag_text = substr($subject, ($matches[0][1] - 30), 60);

For 30 characters before the match and 30 after. If i ve understood correctly the last element in $mathces[i][x] is the offset where the match was found.





相关问题
Find the nth occurrence of substring in a string

This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way. I want to find the index corresponding to the n th occurrence of a substring within a ...

Get Substring - everything before certain char

I m trying to figure out the best way to get everything before the - character in a string. Some example strings are below. The length of the string before - varies and can be any length 223232-1....

Finding a substring of multiple occurences in a string [C++]

is there any STL algorithm or a standard way of finding how many occurences of particular substring are there in a string? For example in string: How do you do at ou the string "ou" appears twice. ...

substring on html.encode

how can I limit the # of characters to display for html.encode? <%= Html.Encode(item.LastName.Substring(1,30))%> error: Index and length must refer to a location within the string.

Drawing in NStextField

If you wanted to implement a highlighting for specific substrings in a NSTextField like on the screenshot (Tweetie.app) how would you do it? :) Tweetie Link Highlighting http://qkpic.com/88c61 Thanks ...

Substring to truncate text?

I m trying to figure out how to truncate the first paragraph, and I ve tried: $div.children( ( p:eq(0) ).substring(0,100)); $div.children( ( p:eq(0) .substring(0,100))); But neither have worked... ...

热门标签