note 81144 added to function.str-replace
| From: | seanatnojunkplz dot boyercentral dot net at osu1 dot php dot net | Date: | Fri, 15 Feb 2008 15:14:32 +0000 |
| Subject: | note 81144 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136175@lists.php.net to get a copy of this message | ||
I wanted to word wrap the text inside of an XML tag for a project I'm working on. This function
will wrap the text inside of any kind of angle-bracket tags, and can be modified to use other tag
types (ie. bbcode)
function wrap_tags($tag, $string, $limit = '200', $break = "<br />\r\n"){
/*------------------------------------------------------
wrap_tags()
by Sean Boyer - February 15, 2008
This function will wrap the text that's inside of a
set of HTML or XML tags.
Useage:
$tag - name of the tag you want to to wrap the
contents of.
brackets!
$string - the string that the tag is
contained in
$limit - the nearest number of chars before
the line wraps (ie. this will NOT cut a word
in the middle to put half on one line, half
on the next
default is 200 chars
$break - the type of line break to use
default is "<br />\r\n"
------------------------------------------------------*/
// Just incase the angle brackets are were included...
$tag = str_replace("<","",$tag);
$tag = str_replace("</","",$tag);
$tag = str_replace(">","",$tag);
$in_str = "/\<$tag\>(.*?)\<\/$tag\>/si";
$lookup = preg_match($in_str, $string, $out_str);
$replace_str = wordwrap($out_str[0], $limit, $break, FALSE);
$string = str_replace($out_str[0], "<$tag>" . $replace_str .
"</$tag>", $string);
return $string;
}
----
Server IP: 66.207.199.35
Probable Submitter: 207.179.177.231
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/81144
Del: integrated -- https://master.php.net/note/delete/81144/integrated
Del: useless -- https://master.php.net/note/delete/81144/useless
Del: bad code -- https://master.php.net/note/delete/81144/bad+code
Del: spam -- https://master.php.net/note/delete/81144/spam
Del: non-english -- https://master.php.net/note/delete/81144/non-english
Del: in docs -- https://master.php.net/note/delete/81144/in+docs
Del: other reasons-- https://master.php.net/note/delete/81144
Reject -- https://master.php.net/note/reject/81144
Search -- https://master.php.net/manage/user-notes.php