Page 1 of 1

Any PHP Gurus here?

Posted: Fri Apr 22, 2005 6:47 am
by bupaje
I have a PHP question and was wondering if there are any php coders who might answer a post?

Posted: Fri Apr 22, 2005 8:11 am
by 7feet
Is PHP particularly wierd? I look at a lot of languages ang try to bang some meaning into my head. A lot of the web specific stuff I don't get at all. I guess that means I'm getting to be an old fart.

Sonny, in the olden days.....


Sorry, that was particularly useless. My apologies. I'd help, but I....can't.

Posted: Fri Apr 22, 2005 8:17 am
by bupaje
Not really. The truth is I just want to modify something simple without having to learn the whole ding dong language. ;) I started reading the tutorials, found what I need but can't quite get it right. I've got so many irons in the fire the last thing I want to do is to go off on yet another side trip for a tiny bit of code. :) I posted on a php forum and hopefully when I wake up I'll have a solution - but then I tend to run to an unrestrained optimism that defies all the actual facts of my existence. ;)

Posted: Fri Apr 22, 2005 2:46 pm
by jorgy
If you don't get an answer on the php board, feel free to post it here. :-)

Posted: Fri Apr 22, 2005 4:46 pm
by bupaje
Ok, will try it here.

I am using the free cms from www.websitebaker.com and I just want a slight modification to add images to the menu and haven't been able to get it right.

This is the relevant line in the function and I have manged to get it altered a bit by looking at examples.

// Function to generate menu
function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a]<img src="/media/icons/[page_title].gif" height="16" width="16" border="0" />[menu_title][/a]</li>',

it works and produces the link but [page_title].gif returns the page name with blanks like so

src="/media/icons/Paint Shop Pro.gif"

all I need is to either collapse the spaces or replace them with '_'

I started working through the tutorials on zend.com and tinkering with ereg_replace and str_replace but truth is I'm more art guy than programmer and I'm stumbling around at this point adding quotes and removing them randonly trying to get it to work.

Just a simple solution if possible; they are releasing new versions every couple of weeks and I've already changed my template twice so this is probably just another patch until the next major version.

I can make a simple example work like so

$phrase = '<p>Here I am</p>';
echo $phrase;
$phrase = ereg_replace (' ','_', $phrase);
echo $phrase;

correctly produces 'Here_I_am'

but getting it in that line the right way is beyond me.

Any help appreciated.

Posted: Fri Apr 22, 2005 7:48 pm
by JohnO
bupaje,

Is there any particular reason you need to eradicate the spaces from the filenames? Is it just to return valid URLs? If the filenames actually have spaces, rather than rename them all you could try the following ...

Code: Select all

... <img src="/media/icons/', urlencode([page_title]), '.gif" ...
which should result in something like...

Code: Select all

<img src="/media/icons/Paint%20Shop%20Pro.gif ...
... which is a perfectly acceptable URL.

It's been a while since I did any serious playing with PHP, so the syntax of the above may not be 100%. :oops:

Sorry if this is not what you're trying to achieve.

beo gesund

Posted: Fri Apr 22, 2005 9:26 pm
by bupaje
This is just sort of a hack until someone creates an image v=nav menu. I am simply taking the page name and appending the .gif. I then name my images to match. I thought I should remove the spaces or add the '_' as I wasn't sure if the image url would be correct with the spaces.

I couldn't get urlencode to work righ yet -I think it may be just the ' " as I get confused over when to use which one; however because of your remark I did upload an image with the spaces in the name and it encodes it automatically as in your example 3D%20Game%20Studio.gif so I guess I don't need to worry about it.

Sort of a mess as I note that the names are case sensitive as well but this should work fine until some 'official' solution is added to the cms.

Thanks very much for the suggestion. :)

Posted: Mon Apr 25, 2005 6:47 pm
by cribble
i wish i knew PHP :( just don't have the time to learn it.

Posted: Mon Apr 25, 2005 8:21 pm
by bupaje
I want to learn everything but I tend to learn just the barest of anything since I jump around. Forcing myself to try to spend my little free time on some classes and Moho when I have play time. :)

More PHP Help

Posted: Wed May 11, 2005 8:09 am
by bupaje
Hi again. I am trying to install the cpdynalinks package from http://www.cplinks.com The links on the produced page are 'wrong' it appears because I cannot upload the required .htaccess file which rewrites the links it looks like.

rewriteEngine on
rewriteRule ^cat/([^/]+).html$ category.php?category=$1
rewriteRule ^page/([^/]+)/([^/]+).html page.php?category=$1&sub_category=$2

Unfortunately SBCYahoo Webhosting doesn't allow you to upload any files with a preceding . or _ and renaming it the code doesn't work. Can anyone who knows PHP clue me in? Can I run this code from a .php file instead of .htaccess somehow?

Posted: Wed May 11, 2005 4:23 pm
by jorgy
I don't think there's an easy way to do it in php. What is happening is that the .htaccess file is a directive to apache, the web server, and happens even before your php script is being run.