Implementing this into phpBB?

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
Without_Boundaries
Registered User
Posts: 75
Joined: Sat Jul 20, 2002 6:35 pm
Location: England
Contact:

Implementing this into phpBB?

Post by Without_Boundaries »

I was kinda bored, so I spent some time making this function:

Code: Select all

function SpaceOut($phrase){

 $letters = 27-1;
 $current = 0;

 $alphabet = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
                   "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " ");
 $replace = array("a ", "b ", "c ", "d ", "e ", "f ", "g ", "h ", "i ", "j ", "k ", "l ", "m ",
                   "n ", "o ", "p ", "q ", "r ", "s ", "t ", "u ", "v ", "w ", "x ", "y ", "z ", "  ");
 $alphabet2 = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                   "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ");
 $replace2 = array("A ", "B ", "C ", "D ", "E ", "F ", "G ", "H ", "I ", "J ", "K ", "L ", "M ",
                   "N ", "O ", "P ", "Q ", "R ", "S ", "T ", "U ", "V ", "W ", "X ", "Y ", "Z ", "  ");


$phrase2 = $phrase;

 for($current=0; $current<=$letters; $current++){
         $phrase2 = str_replace($alphabet[$current], $replace[$current], $phrase2);
         $phrase2 = str_replace($alphabet2[$current], $replace2[$current], $phrase2);
      }
     return $phrase2;

}
It takes a phrase and adds spaces after each character. Please don't say there was an easier way ;)

Anyways, I was wondering how I would turn this into a BBcode, as I have never worked with BBcode before :)
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

Code: Select all

function SpaceOut($phrase)
{
	$str = '';
	for($i=0; $i<strlen($phrase); $i++)
	{
		$j = ord($phrase{$i});
		$str .= $phrase{$i};
		if(($j <= ord('a') && $j <= ord('z')) || ($j <= ord('A') && $j <= ord('Z')))
		{
			$str .= ' ';
		}
	}
	return $str;
}
Way faster than your solution because there are no huge replacements. And easier.
Also i'm sure this can be done with simple regexp, but i'm not good in regexp so can't help with that...
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Without_Boundaries
Registered User
Posts: 75
Joined: Sat Jul 20, 2002 6:35 pm
Location: England
Contact:

Post by Without_Boundaries »

Cool. Thanks. I don't know too many of PHP's functions, so I worked with what I did know :P

Thanks for the code - I'll find out what it all does now

EDIT: Tried it out, and it gave a weird result. Eg:

My code:
T h e r e a r e m a n y e d g e s , b u t a r e t h e y a l l t h i s s u b t l e ?


Your code:
T here a re ma ny edges, but a re they a ll this subtle?


Eh? :?
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

Sorry, i made a stupid typo.

Replace this line:

Code: Select all

if(($j <= ord('a') && $j <= ord('z')) || ($j <= ord('A') && $j <= ord('Z')))
with this:

Code: Select all

if(($j >= ord('a') && $j <= ord('z')) || ($j >= ord('A') && $j <= ord('Z')))
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Anarhists
Registered User
Posts: 29
Joined: Sun Apr 23, 2006 3:12 pm
Location: Latvia

Post by Anarhists »

How can I put this in bbcode MOD? :roll:
Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati »

That is an awful lot of code for what can be done with two lines:

Code: Select all

function spaceout($line)
{
	preg_match_all('#[A-Za-z]#', $line, $carrier);
	return implode(' ', $carrier[0]);
}
..as for the bbcode question - well, I haven't worked with bbcode either, but I thought you might want a simplified function...
Image
Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati »

OK, here's the low-budget bbcode model. This here will implement the function, but it will not create a nice bbcode button for you. Maybe someone else can help create that for you.

OPEN includes/bbcode.php

FIND

Code: Select all

	// [i] and [/i] for italicizing text.
	$text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text);
AFTER, ADD

Code: Select all

	// [space] and [/space] for spacing out letters
	$text = preg_replace("#\[space\](.*?)\[/space\]#sie", "'[space:$uid]' . @spaceout('\\1') . '[/space:$uid]'", $text);
FIND

Code: Select all

?>
BEFORE, ADD

Code: Select all

function spaceout($line)
{
   preg_match_all('#[A-Za-z]#', $line, $carrier);
   return implode(' ', $carrier[0]);
}
You would the write your post as normal and then manually wrap [space] and [/space] around the text you want spaced out, e.g.
[space]some spaced out text[/space]
Image
Anarhists
Registered User
Posts: 29
Joined: Sun Apr 23, 2006 3:12 pm
Location: Latvia

Post by Anarhists »

Oh, BIG THANKS to You, I will try it!!! :D

Hmm, maybe you can help me with this to, but it seems to be not so easy.. :roll: here I made the topic: http://www.phpbb.com/phpBB/viewtopic.php?t=436094
Post Reply

Return to “[2.0.x] MOD Writers Discussion”