Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Line Break

Featured Replies

Page: HERE

 

Referring to the weather stats box on top of the banner, I'd like to make sure that wind speed (m/s) is always on the line below wind speed (kts). The m/s wind speed sometimes begins right next to the kts speed.

 

The php code for this area of the weather stats is as follows:

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts (".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}

 

I've tried inserting nl2br as below. This does not work, 'nl2br' is displayed in the rendered html page...

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts nl2br(".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}

How about a simple <br /> echo ? or am I missing something.

What does $data_clientraw[$clientraw_cpt] usually contain?

 

try this:

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts " . nl2br(sprintf("(" . KTStoMS($data_clientraw[$clientraw_cpt])))." m/s)";}

 

 

Sorry if its garbage, half asleep :lazy:

Or

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts 
"\n"
 (".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}

 

Pat

How about a simple <br /> echo ? or am I missing something.

Where would I place that in the code? And I thought that <br /> tags don't work in php?

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts<br />(".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}

Or

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts 
"\n"
 (".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}

 

Pat

Results in the following error :(:

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/rusclub/public_html/weather/final_clientraw_parser.php on line 35

Parse error: syntax error, unexpected T_STRING in /home/rusclub/public_html/weather/final_clientraw_parser.php on line 35

That wont work anyway, line breaks are ignored by browsers. try the <br /> version and let us know how you get on

Is this the correct code to use (note <br />)?

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
	{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. " kts <br />(".sprintf(KTStoMS($data_clientraw[$clientraw_cpt]))." m/s)";}	
if (eregi('Compass', $types_clientraw[$clientraw_cpt]))

 

I didn't realise you could use html tags such as <br /> within php code (hence this post :))...

sure, $data_clientraw[$clientraw_cpt] ends up being a simple string. Which can then be echo'd. The only only thing you might have trouble with is your using " instead of '

 

if it throws up an error, swap your " for '. like this.

 

if (eregi('Knots', $types_clientraw[$clientraw_cpt]))
	{$data_clientraw[$clientraw_cpt] = $data_clientraw[$clientraw_cpt]. ' kts <br />('.sprintf(KTStoMS($data_clientraw[$clientraw_cpt])).' m/s)';}

 

for an explanation that makes sense... http://www.weberdev.com/get_example-3750.html

<br /> on its own worked. The only problem I have is that it also created a line break on the Gusts stats... Will need to sort that bit out. Thanks for all the help guys :).

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.