fb like links

3 posts by 3 authors in: Forums > CMS Builder
Last Post: September 27, 2012   (RSS)

Re: [rez] fb like links

By gregThomas - September 27, 2012

Hi,

I'm afraid your going to have to modify the way that you use GetRecords to get around this problem. I've done some testing and the method below should work:


foreach($_REQUEST as $key => $item){
if(strstr($key, 'fb_') != FALSE){
unset($_REQUEST[$key]);
}
}
foreach($_REQUEST as $key => $row){
$urlData = $key;
}

// remove page=# so we don't get that by accident
$urlData = preg_replace("/\bpage=\d+\b/", '', $urlData);

//
if (preg_match("/\D*(\d+)(\D+)?$/", $urlData, $matches)) {
$urlData = $matches[1];
}

// load records
list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => "`num` = '$urlData'",
'limit' => '1',
));


This cycles through the request array which contains data that is in the URL, and removes any reference to fields which have 'fb_' in the key. This should leave just an empty array with the key called myrecord-269. The second foreach statement will put the key value against a variable. The two preg_match and preg_replace statements will remove the myrecord- portion of the string.

The final step was to modify the where statement so that it looks for the $urlData variable in the table and doesn't try to get the value from the URL.

You should just need to swap out your current getRecords statement with the code I've provided above.

Let me know if this doesn't work for you.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [rez] fb like links

By gkornbluth - September 27, 2012

Hi Rez,

Came across this:

function similar to rtrim only this will truncate the string at the 1st occurence of any character from $charlist
<?php

function rstrip($string, $charlist = "\t ") {
// removes everything from first occurence of char in charlist to end of string

$charlist = str_split($charlist);
$pos = strlen($string);

foreach ($charlist as $char) {
$pos = min(strpos($string, $char), $pos);
}

$string_stripped = substr($string, 0, $pos);

return $string_stripped;
}

?>


At this URL:

http://php.net/manual/en/function.rtrim.php


Hope it helps,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php