Easy & Dynamic Keyword Highlighting With PHP

Say you are fetching news article data from a database and want to “highilight” (or in this example make bold) specific keywords in the article abstract. Once we have our news article data we need to fetch our keyword data which can also come from a database (recommended) or it could be stored locally in an array.


while($array = pg_fetch_assoc($result))
{
  while($array_key = pg_fetch_assoc($result_key))
  {
    foreach($akeywords as $sphrase)
      $sbody = str_replace($sphrase, "<strong>" . $sphrase . "< /strong >", $soverview);
  }
  pg_result_seek($result_key, 0);
}

Assuming $akeywords is your array of keywords and $sbody is the body of text you want to “highlight”. For each keyword you have the body of text is parsed and if a match is found, a starting <strong> tag is added before the keyword and a closing </strong> tag is added after.

This is a very simple piece of code but it can really come in handy in a number of projects.

- Nicholas

Share

Read Users' Comments (0)

Damn it Jim, I’m a designer not a coder

The title speaks for itself: I’m a designer, not a coder. Then why is it that every job posting I read requires that their art director/creative director is able to write and edit their own HTML, PHP, XML, and of course “action scripting and SEO a plus!” Excuse me? Correct me if I’m wrong here, and know you will, why on earth would you want your senior level designer worrying, nay, writing their own code?

In my last post, I did admit that it is each designer’s responsibility in this web design world we live in, that he or she can at least understand code and its implications to their design: “Being a well-rounded designer does not consist solely of you mastering photo selection and grids, being able to discuss your design with a coder and how they both interact is paramount.” However, that does not mean the ability to write/edit code while the front or back end coder is say, taking a 2 hour smoke break again, or, on their fifth hour of World of Warcraft with their “friends” from Vietnam. Or, not hiring a coder at all. It simply means you can have an intelligent conversation about the code needed to assemble your design, and somewhere down the line, the conversation forks, the designer’s head starts to hurt and the coder returns to his lair.

Personally, I am taking things to the next level professionally. I have indeed returned to school, after a mere fourteen year hiatus, and obtaining my Web Development certificate at a local university. HTML, XML, PHP and MySQL will be, hopefully, pounded into my brain, thusly, giving me that proverbial leg up on the competition. This does not mean I will be hired as a coder, it simply means I have a background and, with all luck, a very good understand of code, what it is capable of doing, and hopefully, writing my own code when and where needed. This does not negate the idea of having an in house coder, never has, never will.

Of course you’ll say, “But Andrew, I’m a designer and I am fully versed in all aspects of code AND designing. What do you have to say to that?” I say bugger off! You are either one of two people: 1. Graduated within the past five years with a web/design degree and your schedule was filled with coding/web classes because that is the state of design schools these days, or 2. You are a freak of nature and must be shot.

Okay, I might have been a bit harsh back there, let me explain. “Back in my day…” (I’m balling my fists up now and shaking them violently at you) there was print. Plain and simple. Brochures, posters, logos and good old mailers. AOL was barely alive and Prodigy was a gleam in someone’s forward thinking eye. Print people taught themselves, in most cases, what they needed to know about this new Information Highway, using their print skills and diving into web jobs they new hardly anything about. I was one of them. In fact, my first web job was with our one and only Stephen Johnson. Hi Stephen. As scary as it might sound, for those of you who know him, he was my first introduction to the world of web design. I still cry at night.

I digress…

I have met and worked with many brilliant coders and amazing designers, however, I have rarely met the brood of the two, where in one person was fluent in both mediums. It has happened, but you want your coders to code and your designers to design. Simple as that. If you have cross-over, count your lucky stars and get back to work.

Back to Warcraft…. I mean work.

Share

Read Users' Comments (0)

Spelunking into the World of Web Design

Good Web design, as subjective as it might be, is still just that, good. For this post, let’s forgo the intricate discussion about how Flash changed the world of web sites, or how Dreamweaver and GoLive made everyone with a pulse and a Mac an over-night web designer. Yeah, I said it, you know who you are. What does need to be addressed is what makes a web site not so much stand out from other sites, but what makes it stand out to you, the user.

Over the past 14 years as a designer I’ve joined (and survived) three start-ups, moved five times, and, hold on to your mouse, held over 35 different jobs. Most of those were in fact freelance or contract jobs. I spent the first six years of my career as a print designer, then in early 2000, I moved blissfully — spelunking’ly’  — into the world of web design. I can safely say that that seemingly eon ago metamorphosis changed my idea and opinion of what design was and can be.

Don’t worry my dear readers, this is not meant to be an online therapy session, far from it. I am not here to discuss what I ate for breakfast this morning, but more importantly, what font I used as a header this afternoon, or maybe what color I chose for a rollover at 2 AM.

Dive, but ask questions
Arguably, one of the most disruptive aspects of bad site design is clutter. This pertains to the not only the navigation, but also the body copy, header and any graphical elements on the page. First and foremost, the designer needs to firmly grasp the idea of hierarchy, then and only then will their site become whole, and with any luck, persuade Google to shine their heavenly beacon in your direction. Of course, most of us are bound to the real “end-user”, the client. The one who signs the checks, pays for rent, and allows us to purchase that shiny new 3G iPhone next week. If he or she wants blinking pink ants dancing around each of their navigation buttons, and wants to see every imaginable area of white space plastered with a Yahoo or Google ad, well sir, thy wish shall be done.

However, designers, don’t be fooled by your vast talents and knowledge of all things design. Never dismiss what should be your most loyal friend, the User Interface developer. The UI design for your site can make or break every aspect of your intensely toiled over design. You may have created the single most beautiful combination of color and font choice, but without a proper UI, you risk the user, with her credit card in hand, to dismiss your site, flicking her proverbial cyber-middle finger at you — closing your window.

To that end, those designers who think they can move the world without the most rudimentary knowledge of code and how it works — not to mention how it will impact your design — pack your up your laptops. Being a well-rounded designer does not consist solely of you mastering photo selection and grids, being able to discuss your design with a coder and how they both interact is paramount. Whether you are working with HTML, PHP, XML or a MySQL database, being able to talk intelligently with a front or back end developer about limitations and potential roadblocks, will not only save you time in the long run, but help you produce that much more robust and error free site. OK, no site is completely error free, but am man can dream.

The best sites, I humbly contest, are those that indeed, keep it simple. That idea was true in design school back in the early 90′s, and it still rings true today. From minimalistic sites like [ Craiglist ] and [ Apple ] to the robust [ CNN ] and [ Adobe ], they all have one thing in common: clean, simple, and best of all, legible content and a user-friendly layout. From soccer moms and CEO to teens and ex white house press secretaries, beyond all other needs and wants a site has to offer, they want to be able to find what they are looking for and get on with their double-clicking afternoons.

As reference, please visit: [ webdesignfromscratch ] It offers a wealth of knowledge about, albeit, mostly Web 2.0 remarks, it gives an informed direction of site design, both what can go right, and what can go very wrong.

Happy Spelunking!

Share

Read Users' Comments (2)

 Page 3 of 3 « 1  2  3