Style <br />?

Is it possible to style a break <br /> similar to how you would style the paragraph <p> tags?

Debbie

P.S. Is this <p> called a “Tag” or an “Element” or are the terms synonymous?! :-/

You can certainly apply some styles to <br>s. But I use them extremely rarely, so I’d first question whether you really need them.

A paragraph is an “element”, but <p> and </p> are “tags”. (That’s how I understand it, anyhow. :slight_smile: )

So what do I do with this new dilemma…

If a User writes a book - 5 paragraphs - in my TextArea in the Form, and submits it, the browser just inserts hidden
wherever there are carriage returns. But I have no “hooks” (i.e. <p></p>) to style?!

And while I can use something like nl2br in PHP, I still have no proper way to style my pseudo-paragraphs?! :mad:

(That’s a pretty STUPID design on the part of the browser engineers or whoever?!)

Because my Q&A Form is designed to get people to type mini-books, I don’t want this big slop of horrendously long lines of TEXT followed by an occasional <br />?! YUK!!! :mad:

(Example of just 2 Sentences to make my point…) :wink:

Elizabeth, New Jersey, when my mother was being raised there in a flat over her father’s grocery store, was an industrial port a quarter the size of Newark, dominated by the Irish working class and their politicians and the tightly knit parish life that revolved around the town’s many churches, and though I never heard her complain of having been pointedly ill-treated in Elizabeth as a girl, it was not until she married and moved to Newark’s new Jewish neighborhood that she discovered the confidence that led her to become first a PTA “grade mother,” then a PTA vice president in charge of establishing a Kindergarten Mothers’ Club, and finally the PTA president, who, after attending a conference in Trenton on infantile paralysis, proposed an annual March of Dimes dance on January 30 – President Roosevelt’s birthday – that was accepted by most schools.<br />

Their honour precarious, their liberty provisional, lasting only until the discovery of their crime; their position unstable, like that of the poet who one day was feasted at every table, applauded in every theatre in London, and on the next was driven from every lodging, unable to find a pillow upon which to lay his head, turning the mill like Samson and saying like him: “The two sexes shall die, each in a place apart!”; excluded even, save on the days of general disaster when the majority rally round the victim as the Jews rallied round Dreyfus, from the sympathy–at times from the society–of their fellows, in whom they inspire only disgust at seeing themselves as they are, portrayed in a mirror which, ceasing to flatter them, accentuates every blemish that they have refused to observe in themselves, and makes them understand that what they have been calling their love (a thing to which, playing upon the word, they have by association annexed all that poetry, painting, music, chivalry, asceticism have contrived to add to love…<br />

Follow me?!

Debbie

Hm, as a quick experiment, you could try something like

br {display: block; margin-top: 20px;}

But I’d like to know if there’s a better way—via PHP—to add in <p> tags around that text. But I can’t advise on that. Surely it must be possible with basic PHP, though. CMSes add in <p> tags.

To start with the entire content entered should be wrapped inside <p> and </p>

Then whenever two
occur with nothing but whitespace in between you replace them with </p><p> which can be easily done in PHP using a regular expression. Any single
should generally be ignored so that the text can adapt to fit the width available.

Doing that you wouldn’t end up with any <br/> at all.

I thought I knew Regex fairly well, but I’m unsure of how to do what you are describing.

Care to share how you’d do that?

Any single
should generally be ignored so that the text can adapt to fit the width available. Doing that you wouldn’t end up with any <br/> at all.

Wouldn’t you want to use a Regex to replace an
with a <br /> ??

Thanks,

Debbie

if your text are only includes Ps, you could do it with a lowly sequenced str_replace. for this it is faster, and simpler to read.


$content= '<p>'.$content.'</p>';
$content= str_replace("\
\
","</p><p>")
$content= str_replace("\
","<br \\>");

To allow for someone having entered spaces between the linefeeds you could use:

$content= str_replace("\
\\s*\
","</p><p>");

I’d probably follow that with:

$content= str_replace("\
",""); 

since except for poetry and a few other rare situations the content of the paragraphs should just fill the available width without linefeeds in specific places that could cause words to appear on lines by themselves.

If you are going to replace them with <br/> tags then don’t include the unnecessary space in the tag (that was only necessary to get the code to work with Nescape 4).

$content= str_replace("\
\\s*\
","</p><p>",$yourstring);  

It’s a good point, but I dont think str_replace() works with regex. so you may have to go with preg_replace() for that.

You’re right - I didn’t look closely enough at which function was being used and had mistaken the one for the other since I had been thinking that a regex solution was the best option from the start.