What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » String manipulation in PHP

String manipulation in PHP
Author: Message:
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: String manipulation in PHP
This may not be the most efficient way to do it but it works.

code:
<?php
$str = "index.php?spgmGal=rav&spgmPic=7&title=something#spgmPicture";

echo transformlink($str);

function transformlink($str) {
#get title
preg_match('/title=[A-Za-z0-9 ]+/', $str, $matches, PREG_OFFSET_CAPTURE);
$title = substr($matches[0][0], 6);
   
    #check if spgmGal is there
    if (preg_match("/spgmGal=[A-Za-z0-9 ]+/", $str)) {
        preg_match('/spgmGal=[A-Za-z0-9 ]+/', $str, $matches, PREG_OFFSET_CAPTURE);
        $spgmGal = substr($matches[0][0], 8);
    } else {
        $spgmGal = null;
    }

    #check if spgmPic is there
    if(!is_null($spgmGal)) {
        preg_match('/spgmPic=[A-Za-z0-9 ]+/', $str, $matches, PREG_OFFSET_CAPTURE);
        $spgmPic = substr($matches[0][0], 8);
    } else {
        $spgmPic = null;
    }

#get spgmPicture anchor
preg_match('/#[A-Za-z0-9 ]+/', $str, $matches, PREG_OFFSET_CAPTURE);
$spgmPicture = $matches[0][0];

#return transformed link
$thelink = (!is_null($spgmGal)) ? '/'.$title.'/'.$spgmGal.'/'.$spgmPic.$spgmPicture : '/'.$title.$spgmPicture;

return $thelink;
}

?>
[Image: sig.png]
10-05-2007 10:24 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
String manipulation in PHP - by rav0 on 10-05-2007 at 12:50 PM
RE: String manipulation in PHP - by hmaster on 10-05-2007 at 10:24 PM
RE: String manipulation in PHP - by rav0 on 10-06-2007 at 02:35 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On