Tuesday 28 August 2012

Convert Title Into Slug URL Using PHP

No comments:
During my job while uploading content for MPS project, i am always facing the same problem. Its always make me become lazious to change all link title into slugify format manually. I am weird why this new portal system can't handle this conversion.

To overcome this issues, i've created a new php code to assist my work. This is very basic code based on Regex pattern to remove all non alphanumeric character and change all spaces into dashes.

Here is what i want for this code:

1. Remove non alphanumeric chars.
2. Change spaces into dashes.
3. All must lowercase.

To fulfill above rule here the simplest code:

function slugify($txt)
{
  // replace all non alphanumeric into dashes
  $text = preg_replace('/\W+/', '-', $txt);

  // trim and lowercase
  return strtolower(trim($txt, '-'));
}
?>

Example scenario:

Mistery of Mine & How to : Extracting IP Values IPv6 2012 under 10% value

Will converted into:

mistery-of-mine-how-to-extracting-ip-values-ipv6-2012-under-10-value

Hope it help others.




Upload Content For MPS

No comments:
Assalamualaikom and Good day.

Yesterday is my full office time to finishing MPS portal and its takes 7 working days. Lots of things need to work on.

There are currently hundreds of portal need to migrated to new system version. Some of it need to manually copy paste the existence contents to a  new one. My portal is one of that scenario and the pain is i need to finish almost 98% of content. My other friends got better portal with already have content at least 30-70% and this is paid job.

Its nice if we can get extra salary than ordinary one especially after Aidilfitri break.Since last month this work take lots of my time and i need to work over nite at office. Its great some time but not mostly.

Well, hope this work done early.

Monday 27 August 2012

YS Friendz Sections

No comments:
 Assalamualaikom w.b.t and good day.


Today i would like to introduce my new blogging section called YS Friendz. There are lots of Young Skalian together working with SKALI and its best part to create memorable stuff via blogging.

What i will do?

Fisrt i will introduce their blogs and little bit about themselves. Then we will collaborate each other to linking and promote our blog so everyone can know each other.

So, what waiting for? If you want to become early YS to introduce yourself just drop me your comment to this post.

Hope Great day and enjoy...

Friday 24 August 2012

PHP Web Scraper Basic Lesson

No comments:
In previous post i've told that PHP web scraping involving several flows techniques. Today i will showing you a very basic PHP Web Scraping.

For example i will show you how to extract latest news from http://www.skali.net/web/guest/news and sort its headlines into the list.

Skali.Net News Page

Fisrt we need a very php basic code to obtain a copy of Skali News. For basic lesson i will using this code:
<?php
 $data = file_get_contents(
'http://www.skali.net/web/guest/news'
);
?>

file_get_contents is quick code to grab remoted site as string code. $data variable containing Skali News html source code.

Next, we need to parsing its headlines. For basic i will using Regex method. Before using Regex, we need to know which pattern of News Headline and what its unique angle compare to others htmls code.

Skali News Html Source Code

Refer to the screen snapshot, i have highlighted the text pattern that describing Skali news headlines.

As example:

<span style="font-size: larger;">EmbunWeb.com Are at Wordcamp Malaysia!</span>

 My Regex pattern should looks like this to match all headlines:

#<span style="font-size\: larger;">(.*?)<\/span>#is

 
The Regex pattern need to match just between <span> with font larger style. The matched pattern need to dump as array list to make sure its success.

<?php
 $data = file_get_contents('http://www.skali.net/web/guest/news');
 $regex = '#<span style="font-size\: larger;">(.*?)<\/span>#is';
 preg_match_all($regex,$data,$match);
echo '<pre>';
 echo print_r($match[1]);
echo '</pre>'; 
 ?>

Here how output using my localhost testing system:


Weehee...we got it!!
Output:

Array
(
    [0] => EmbunWeb.com Are at Wordcamp Malaysia!
    [1] => Kepakaran tempatan memacu MEB Oleh Aimi Aizal Nasharuddin
    [2] => Govt websites have markedly improved: MDeC
    [3] => Skali sees 20% growth in web hosting revenue
    [4] => Utusan Malaysia - Program SPIKE lahirkan Aisoft Solution
    [5] => The Edge Malaysia - Sure and Steady Skali
    [6] => Skali Looks Forward To Stage 2 Of MPS Project Feb 8 2010
)

Php Web Scraper Its Hard?

No comments:
Php Web Scraper

Assalamualaikom and Good Day everyone.

Did you know about PHP Web Scraper?

Web Scraper is my favorite technology involving PHP server coding. Its very interesting stuff to explore. Today i will explain a simplified overview of how data gets to and from the web browser to our php applications.

Web Scraping
The flow of process starting by copying any site html pages and then filtering or extracting with several php parsing techniques.

To grab any page we can use Curl (its my priority), HTTP stream socket, or others library like Snoopy. I always prefer using Curl due its user friendly functioning and faster. 

To extract any portion of html, text or any element of scraped site we need a better php libraries such as php SimpleDom, PHPQuery or as simple DomXpath. Using common ordinary regex and string manipulation will take lots of time to coded.

Next post i will show you several technique to using Curl as web grabber.

Good Luck!

Lesson To PHP Web Scraping



Thursday 23 August 2012

Happy Aidilfitri

No comments:
Today i wishing you all

"Selamat Hari Raya Aidilfitri"

I would like to take this opportunity to wish all my Muslim reader and friends a happy Selamat Hari Raya Aidilfitri 2012. Hope this Raya brings joy and happiness to you and your family.

Syukran...

About

No comments:
Assalamualaikom w.b.t and Good Days,

Currently i am a Young SKALI for 2nd Intake 2012 and taking Network Admin (ITD) and also a web builder freelancer.

I like PHP programming and HTML. Its a basic website creation. PHP is web server side language and HTML is client side language for web appearances.


I specialize and design

Websites, Blogs, Posters, Wedding Albums, Business Cards, Corporate Identity, Branding,

and offers ranges of

creative services, from graphics design to website development.


I am a website builder based in KL with over 2 years of freelance graphic experience. I design clean, smart webpage and minimal design is always my preference and most of my skills and knowledge are self taught.

I'm a graduated of Diploma Engineering Electric & Electronic Communication from University Technology of Malaysia (UTM).

Check out my portfolio to experience unique and customized websites & blogs, for personal use or grow your business.