Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
NoFantasy
Worker
Worker



Joined: Apr 26, 2005
Posts: 114

PostPosted: Mon Aug 29, 2005 11:37 am Reply with quote

I'm trying to replace the linebreaks found in nuke_bbposts_text.

My question is:
What are the linebreaks found in nuke_bbposts_text?
Is str_replace the right thing to use?

$message = str_replace("Linebreaks_in_bbposts", "<br>", $message);
 
View user's profile Send private message
64bitguy
The Mouse Is Extension Of Arm



Joined: Mar 06, 2004
Posts: 1164

PostPosted: Mon Aug 29, 2005 1:11 pm Reply with quote

Can you clarify the problem and exactly what you are trying to achieve? I not sure why you would want to remove line breaks as text and other functions would all run together making things more difficult to read.

_________________
Steph Benoit
100% Section 508 and W3C HTML5 and CSS Compliant (Truly) Code, because I love compliance. 
View user's profile Send private message
NoFantasy







PostPosted: Mon Aug 29, 2005 1:38 pm Reply with quote

My neverending problem, i'm sorry...It's so d*** hard to explain in good english (i'm norwegian).

I'm trying to pull the text from nuke_bbposts_text, and let the selected (corresponding to the first post in each thread). Next step is to convert the text (with BBcode, linebreaks, etc....) so that overLIB can use it in javascript. (part of the problem seems to be the linebreaks, overLIB will not process them)
Finally the result will show up as a tooltip-box over each thread-link so the user can determine some of the content before entering the thread itself.

The idea is based on OnMouseOverTitle-mod from http://www.phpbbhacks.com/download/3691 ...but i belive what i'm trying to achive here is a bit more complicated...and maybe useful...
 
64bitguy







PostPosted: Mon Aug 29, 2005 1:49 pm Reply with quote

Why not try to use an XML/RSS "backend.php" type function to extract and summarize the data and then use an RSS block to post it back? This way you don't have to worry about breaks and code.
 
NoFantasy







PostPosted: Mon Aug 29, 2005 1:57 pm Reply with quote

Beacuse I haven't got a clue how to do that... Embarassed
BTW, i found the linebreaks...
Code:
\r\n


I have this thingy working 90% now, I was hoping to get it at least 99%. Not saying xml/rss is a better way, it's just that I don't even know where to begin...
 
NoFantasy







PostPosted: Mon Aug 29, 2005 2:05 pm Reply with quote

*lol* Guess some of you getting a good laugh at this, but i'll post it anyway...This is my strip-text-function so far:
Code:
function bbencode_strip($message, $uid)

{
   $message = strip_tags($message);   
   $message = str_replace("[url]","", $message);
   $message = str_replace("[url=","", $message);
   $message = str_replace("[/url]", "", $message);
   $message = str_replace("[img]","", $message);
   $message = str_replace("[/img]", "", $message);
   $message = str_replace("[color=","", $message);
   $message = str_replace("[/color]","", $message);
   $message = str_replace("'", "”", $message);
   $message = str_replace('"', "”", $message);
   $message = preg_replace("/\[url=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\]/si", "", $message);
   $message = preg_replace("/\[img=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\]/si", "", $message);
   $message = str_replace("[/url:$uid]", "", $message);
   $message = preg_replace("/\[.*?:$uid:?.*?\]/si", '', $message);
   $message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
   $message = str_replace("\r\n", "<br>", $message);
   return $message;
}

This code is from a similar Mod mentioned over, but made/modified:
Title: Mouse hover topic preview
MOD Author: Shannado (Sven)
Modified by Dauthus

I know the replacements are far from perfect, but at least I got myself a hobby for some days Very Happy
 
VinDSL
Life Cycles Becoming CPU Cycles



Joined: Jul 11, 2004
Posts: 614
Location: Arizona (USA) Admin: NukeCops.com Admin: Disipal Designs Admin: Lenon.com

PostPosted: Mon Aug 29, 2005 2:33 pm Reply with quote

Looks good!

NoFantasy wrote:
Code:
   $message = str_replace("\r\n", "<br>", $message);

That would have been my suggestion for replacing the linebreaks...

If you simply want to get rid of them, I'd use this:
Code:
    $message = rtrim($message, " \r\n ");

_________________
.:: "The further in you go, the bigger it gets!" ::.
.:: Only registered users can see links on this board! Get registered or login! | Only registered users can see links on this board! Get registered or login! ::. 
View user's profile Send private message Visit poster's website ICQ Number
NoFantasy







PostPosted: Mon Aug 29, 2005 2:49 pm Reply with quote

It seems Only registered users can see links on this board! Get registered or login! can process br-tags, so i'll primarily keep them. Looks better on the tooltip.

The headache is how to remove all the BBcode before processing further.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Tue Aug 30, 2005 1:33 pm Reply with quote

Why not just use
Code:
$message = nl2br($message);
 
View user's profile Send private message
NoFantasy







PostPosted: Tue Aug 30, 2005 7:15 pm Reply with quote

I'm not sure at all why, but
Code:
$message = nl2br($message);

does not work with my script at all.

There was still some bugs with the previeously \r\n, but I found a more robust replace:
Code:
$message = preg_replace("/(\r\n|\n|\r)/", "", $message);


Why it works in a different way, I don't know. I got rid of the remaining bugs with the line breaks.

Still got an issue with the line breaks in
Code:
'TOPIC_TITLE' => $topic_title,
(found in viewforum.php)

Usually, there's no line breaks in the forumtitle, but in a few imported rss-feeds, the title contains line breaks (don't ask how or why, it's not br-tags, neither are any line breaks shown in phpMyAdmin...only visible in the browsers "view source")

Since javascript will read ' as a part of the script-code i had to remove them. I'm now trying to remove line breaks in forumtitle as well:
Code:
'TOPIC_TITLE' => $topic_title = preg_replace("/(\r\n|\n|\r|')/", "", $topic_title),

Without any luck....a few linebreaks remain in forumtitle...
 
Raven







PostPosted: Tue Aug 30, 2005 8:10 pm Reply with quote

nl2br() translates all newline characters to <br /> tags. See http://us3.php.net/manual/en/function.nl2br.php. To say it doesn't work at all is very strange. What I meant was to replace this one line
Code:
$message = str_replace("\r\n", "<br>", $message);
with
Code:
$message = nl2br($message);
 
NoFantasy







PostPosted: Tue Aug 30, 2005 9:01 pm Reply with quote

Well, it'd probably work, if it wasn't for the \r It seems to replace all the rest.

Anyways, the use of nl2br as suggested, did not work in my case.

I'll make an effort to post the whole thing tomorrow, if any want to try this out themselves.
 
VinDSL







PostPosted: Wed Aug 31, 2005 2:23 am Reply with quote

NoFantasy wrote:
I'm not sure at all why...

Heh! I love watching this process take place!

I attacked 'str_replace', 'preg_replace', 'rtrim', et cetera, on my own, in the middle of the night, so to speak. I felt so alone, but at the same time, so empowered.

I can see all this unfolding in you as well, simply by watching your 'thinkings' take place, as expressed in this thread. Basically, you're 'talking' out loud, but that's okay.

If it's of any consolation, you are getting a handle on 'it'. Hang in there!
 
NoFantasy







PostPosted: Wed Aug 31, 2005 8:57 am Reply with quote

LOL, thanks VinDSL
And you are right, mostly i do 'think loud' here. None of my friends IRL has knowledge of either php, nuke or sql, so i guess it's better to think loud here, instead of all-by-myself. And the answers you all are giving, makes a difference from other forums, where newbies often gets a negative respons.
 
NoFantasy







PostPosted: Wed Aug 31, 2005 12:02 pm Reply with quote

If anyone wants to review the whole Tooltip/First post preview, I have posted it Only registered users can see links on this board! Get registered or login!.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©