Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,670 members, 7,823,896 topics. Date: Friday, 10 May 2024 at 05:38 PM

Application In Php - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Application In Php (1499 Views)

Creating UWP Application In C# Or C++ (xaml) / Simple CRUD Application In PHP And Mysql / Running Python Codes In Php (2) (3) (4)

(1) (Reply) (Go Down)

Application In Php by clerisy: 6:56am On Feb 09, 2012
I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?
Re: Application In Php by ektbear: 8:24am On Feb 09, 2012
Couldn't you sprintf() to a string, then process the string only outputting 50 characters at a time?
Re: Application In Php by raghubodi: 11:02am On Feb 09, 2012
When it comes to security, remember that in addition to actual platform and operating system security issues, you need to ensure that you write your application to be secure. When you write PHP applications, apply these seven habits to make sure your applications are as secure as possible:

Validate input
Guard your file system
Guard your database
Guard your session data
Guard against Cross-Site Scripting (XSS) vulnerabilities
Verify form posts
Protect against Cross-Site Request Forgeries (CSRF)
Re: Application In Php by delomos(m): 6:11pm On Feb 09, 2012
In addition to @ekt_bear's response, sprintf might not always be practical (especially if you're not sure the original lines you're expecting, so let's say you have your lines in $lines, you can do:

$excerpted_lines = substr($lines, 0, 50); //chops the line into, but this can chop things off in the middle so ,

//, let's clean it up
$lines_array = explode(' ', $excerpted_lines);
$word_count = count($lines_array);


// now we have the cleaned up version,
$clean_lines = impode(' ', array_slice($word_count,0, $word_count -1));

then I can do something like

echo $clean_lines . ", ";

I'm sure you can play with this in more interesting ways, here is a reference to the main PHP functions used here:
http://dochub.io/#php/substr
http://dochub.io/#php/implode
http://dochub.io/#php/explode
http://dochub.io/#php/array_slice
Re: Application In Php by DonSegmond(m): 12:36am On Feb 15, 2012
Whatever you are doing, you are doing wrong. Stop and look up how to use a template class.
Re: Application In Php by delomos(m): 1:45am On Feb 15, 2012
DonSegmond:

Whatever you are doing, you are doing wrong. Stop and look up how to use a template class.

Does everything have to be OOP?

Perhaps when all you have is a hammer, everything looks like a nail, ?
Re: Application In Php by DonSegmond(m): 2:29am On Feb 15, 2012
delomos:

Does everything have to be OOP?

Perhaps when all you have is a hammer, everything looks like a nail,  ?

You don't need OOP to use a templating library. I'm not an OOP nuts, I've been programming for almost 20yrs. Before the world went OOP crazy. I started out with Basic, C and assembly language. I've never been a fan of OOP, It's just in the last year that I've noticed that for really huge project it's worth knowing. Sure, you can create a million lines of code straight up procedural style, but boy will you wish to have done it with OOP.

The only reason not to embrace OOP is due to the expensive runtime cost, but few people actually write code so time critical today.

For very small codes, experiments, no need for OOP. But with that said, PHP template doesn't need to be OOP involved at all. It simply boils down to separating data and code. And the OP sounds like he has his code and data mixed up.
Re: Application In Php by delomos(m): 2:54am On Feb 15, 2012
DonSegmond:

Stop and look up how to use a template class.

I'm curious to know what that ^^ means in relation to the question the OP asked?
Re: Application In Php by DonSegmond(m): 3:13am On Feb 15, 2012
delomos:

I'm curious to know what that ^^ means in relation to the question the OP asked?

OP said, "outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters."

From what OP said, we can reach some facts.
1) So his program outputs driving directions.
2) These directions contains long sentences.
3) There are more than one of these sentences, and they seem to exceed 50 characters.

Using the above facts, I can deduce that OP is dealing with data, and by using a template pattern, he can separate his data from his code. Furthermore, this can help down the line if say he wants his program to output driving directions in multiple languages. Today english, perhaps tomorrow yoruba, then french, it's just good programming practice. However, he needs not use a template library. He can just as easily throw them into constant arrays and have all the data in one file. But hey, I encourage good practice from the get go, you don't have to wait to get big to act big, start practicing now. lol.
Re: Application In Php by delomos(m): 3:18am On Feb 15, 2012
clerisy:

I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?
^^^^
Re: Application In Php by DonSegmond(m): 3:34am On Feb 15, 2012
delomos:

^^^^

OP said "I am writing an application in PHP"
So I reckon that OP can accomplish it in PHP, rather they want to know " that no line exceeds 50 characters.".

With that said. delomos, where is this going? grin
Re: Application In Php by delomos(m): 12:51pm On Feb 15, 2012
DonSegmond:


With that said. delomos, where is this going? grin

To have you answer the exact question asked; many might benefit from it -- just saying "look up template class" isn't an answer, point us to where to look or give a script example (that solves the problem), that way the OP (and other Googlers) know where to proceed rather than confuse the OP even more.

Someone asking how the format a string in PHP isn't really one to be throwing abstract concept at.

That said, can you finish answer the question (with the recommendation above) so you can actually be helpful to the OP. Or see the answers already given below.

(1) (Reply)

API Using Python / Learn Figma – UI/UX Design Essential Training Course / My Story: What It Takes To Be An Intensive Ethical Hacker

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.