Results 1 to 15 of 24
-
August 12th, 2005, 01:21 PM #1
PHP -> STRTR() function problem....
Hi,
I'm making a function to replace in a textbox: [b] for <b> ... and that kind of thing... [br] for <br>... etc, so somaone can write smilefaces and then I can replace that by a image [:-)] =>
my function is:
My problem is... there is a way to count the number of "[" (in this case) so if they don't match with the numer of "]" an error sintaxis appears... bicouse if someone write:PHP Code:function colorearTexto($str){
$RESERVED=array("[b]"=>"<b>","[/b]"=>"</b>","\n"=>"<br>"); //... etc
return strtr($str, $RESERVED);
}
hello [b]my name is [/b
... etc etc blabla
and forgot the "]", i don't want that all the text appears in bold...
or there is another way??
-
August 12th, 2005, 01:32 PM #2
there is a function to make something like this?
example: replace(" * ","<b> * </b>", $str); //being the * anything between the tags... ????????????
-
August 12th, 2005, 01:34 PM #3
your looking for regular expressions.
i'd recommend googling Regular Expressions... and checking out www.php.net/preg_replace
that should help you out
got pwnt?
-
August 12th, 2005, 01:51 PM #4
YYYYYYYYEEEEEEEEEEEAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!! ! THAnkS .harish YAEEAAAAAAAAAAA!!!!!
-
August 12th, 2005, 02:06 PM #5
one last question, this function eliminate the "<script>" tags... but, how do I do to replace the "<script>...</script>" for "[script]...[/script]"
... I tell you this bicouse I don't know what this means: '@<script[^>]*?>.*?</script>@si'PHP Code:$busqueda = array ('@<script[^>]*?>.*?</script>@si');
$reemplazar = array ('');
$texto = preg_replace($busqueda, $reemplazar, $documento);
-
August 12th, 2005, 02:09 PM #6
-
August 12th, 2005, 02:24 PM #7
I 'm trying to make something like the Quick Reply feature of this forum... where I use tags [...] and are replaced by something... like the [_QUOTE_] tags (without the _ )
so I can make a function that take this :[-b]Bold[-/b] and return < b > Bold < / b >
-
August 12th, 2005, 02:30 PM #8
-
August 12th, 2005, 02:37 PM #9
Thanks... that work! las question... what are all that simbols in the first arguments of the function preg_replace?? '/\[b\](.*)\[/b]/i' ??
whats the diference between:
preg_replace('/\[b\](.*)\[/b]/i', '/<b>${1}</b>/', $content);
and
preg_replace('[/b]!', '<b>${1}</b>', $content);Last edited by bandinopla; August 12th, 2005 at 02:40 PM.
-
August 12th, 2005, 02:44 PM #10
They're probably about equivalent.
/: start the regular expression (these must enclose the entire expression)
\: Escape the next character. It makes it so the next character doesn't mean anything.
[: the start of the pseudo-tag
b: the bold character
\: escape the meaning of the next character
]: the end of the pseudo-tag
(: start the area to remember, defined as a variable when replacing
.: any character
*: 0-Infinte number of the previous character
): close the variable
\: escape the next character
[: start pseudo-code
/: end tag slash
b: end tag b
\: escape next character (although not necessary, recommended). I forgot it in my last post.
]: end closing tag
/: end regular expression
i: make the regular expression case-insensitiveLast edited by Jeff Wheeler; August 12th, 2005 at 02:48 PM.
-
August 12th, 2005, 02:47 PM #11
uuuooouu!!!!
YEEEAA!!!! Thats what I talking about!!! SUper THANKS nokrev
yea!!
-
August 12th, 2005, 02:48 PM #12
-
August 12th, 2005, 02:48 PM #13Here's a working example that will work on any HTML tag. All the $documento's at the top are there for you to text and use.PHP Code:
<?php
//$documento = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
//$documento = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
//$documento = ' <head>';
//$documento = ' <title> </title>';
//$documento = ' <script type="text/javascript" src="js.js"></script>';
//$documento = ' </head>';
//$documento = ' <body onload="myDate()">';
//$documento = ' <h1 class="top">Title</h1>';
$documento = ' <b>Some info</b>';
$busqueda = '/<([\/\!])?([\w]{1,})([^>]*)?>/i';
//$reemplazar = '[$1$2$3]';
$reemplazar = '[$1$2]';
$texto = preg_replace($busqueda, $reemplazar, $documento);
echo '<pre>' . $texto . '</pre>';
?>
There are two $reemplazar's there the one that's commented (with $1$2$3) would include everything that's included with the tag (id, classes, other HTML tag attributes).
So...if you used:
You would see:Code:$documento = ' <h1 class="top">Title</h1>';
It should work on any HTML tag you need.Code:// When $reemplazar = '[$1$2$3]'; // You'd see: [h1 class="top"]Title[/h1] // When $reemplazar = '[$1$2]'; // You'd see: [h1]Title[/h1]
-
August 12th, 2005, 02:50 PM #14
-
August 12th, 2005, 02:53 PM #15
Thanks Ankou!!
Similar Threads
-
PHP To Flash Problem
By gravenine in forum Flash IDEReplies: 0Last Post: July 6th, 2005, 04:25 PM -
Tighter Integration between Oracle and PHP
By red_A in forum RandomReplies: 0Last Post: May 17th, 2005, 04:50 AM -
trying to grasp applying generic function to mc onEnterFrame's
By RASMedia in forum ActionScript 2 (and Earlier)Replies: 7Last Post: December 17th, 2004, 01:14 PM -
FMX2004 > PHP > MySQL > PHP > FMX2004
By ScriptFlipper in forum ActionScript 2 (and Earlier)Replies: 6Last Post: January 6th, 2004, 06:10 AM -
PHP form post problem (simple)
By slow56kftp in forum Server-Side (PHP, SQL, ASP.NET, etc.)Replies: 1Last Post: August 5th, 2002, 01:43 AM

Reply With Quote



Bookmarks