Page 1 of 1

nl2p

Posted: Thu Apr 15, 2010 10:14 am
by orko
Hi,

warning - decent css/html skills and reasonably sharp but a total php noob.

In one of the html input fields of the content management (heavily tweaked wordpress and equally customized nextgen gallery) setup I wish to achieve automatic paragraphs. As the field I wish to have this at is the image description a <P> infront every word will not work for me. It would make for an ugly mouse hover tooltip, and search engines would also not be thrilled.

I've been playing with nl2br and nl2p but it's getting the best of me and I can't figure it out.

This is the php field corresponding in the content manager

Code: Select all

<textarea name="alttext[<?php echo $pid ?>]" style="width:95%; margin-top: 2px;" rows="6" ><?php echo stripslashes($picture->alttext) ?></textarea>
this was what i thought would do the trick but it does nothing

Code: Select all


<textarea name="alttext[<?php echo $pid ?>]"<?php function nl2p($pid) {return "<p>" . str_replace("\n", "</p><p>", $pid) . "</p>";}?> style="width:95%; margin-top: 2px;" rows="6" ><?php echo stripslashes($picture->alttext) ?></textarea>
Your help is much appreciated!

Orko

Re: nl2p

Posted: Thu Apr 15, 2010 11:02 am
by Reviresco
I've found that "\n" doesn't always get the line breaks. Try "\r" and/or "\r\n".

Re: nl2p

Posted: Thu Apr 15, 2010 11:08 am
by AbraCadaver
I'm at a loss as to the HTML part and what is going to happen with the name property, but you defined the function but you didn't actually call it. Try this:

Code: Select all

<?php function nl2p($pid) {return "<p>"  . str_replace("\n", "</p><p>", $pid) . "</p>";}?> 
<textarea name="alttext[<?php echo nl2p($pid); ?>]" style="width:95%; margin-top: 2px;" rows="6" >
<?php  echo stripslashes($picture->alttext); ?>
</textarea>
Ideally, if you use this function then you should move it to a central file that gets included in all of your pages.

Re: nl2p

Posted: Fri Apr 16, 2010 2:46 am
by orko
thanks both.

I've used using both your suggestions but neither work sadly.

Here's what happens and what i want to achieve.

I wish to have the first field formatted such that every line becomes a paragraph. As you can see in the second field I could do this via <p> in front of every word but as this is the image 'alt' this would look bad in the tooltip and is bad for my seo efforts.
Image

With AbraCadaver's suggestion i get

[text]Fatal error: Cannot redeclare nl2p() (previously declared in[/text]
which leads to the line where i posted the code.

This happens in the 2nd html input field, subsequent ones don't even appear, the page stops there completely. The content manager has a input fields for every image, which gets 'replicated
Image

Any help is very much appreciated, this one's getting the better of me!

Orko

Re: nl2p

Posted: Fri Apr 16, 2010 7:23 am
by roders
I understand what you're trying to do but unless you use a javascript tooltip, to get a formatted title for your image i don't see how you will do it, i've done all kind of research on this and all seems to conclude that once in html \n has to <br/> there is no other option.

Re: nl2p

Posted: Fri Apr 16, 2010 8:44 am
by orko
thanks roders, the way the tool tip looks is the least of my problems. I just don't want unsightly <p>'s on rollover, it its all in one line, perfect.

The main objective is how it looks in the image overlay, which uses the content from the image's description. Sorry if I didn't make that clear in my other posts.

Re: nl2p

Posted: Sat Apr 17, 2010 11:23 am
by orko
any one any further ideas?

thanks