Forum Moderators: coopster

Message Too Old, No Replies

Condensing a String?

         

ahmedtheking

5:46 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've set up a php script to write some CSS as a string (as it's dynamic CSS with colours changing depending on vars...)

But when i try and move this string on a seperate page, for example a pop up window, (eg <a href=somepage.php?css=thecssstring>) but because the string is so long, it doesnt work!

Is there anyway to condense the data and then spit it out again? Ive tried base64_encode but it doesnt work!

kazecoder

7:52 pm on May 13, 2005 (gmt 0)

10+ Year Member



Exactly how long is the string? I have passed strings with many many characters and its went fine. A few notes:

A) You cant have any spaces in any of the values or it may cause problems with the encoding

B) If you have spaces you can use the pass it like this:

$string = "This is my string";

$sending_string = str_replace(" ", "_", $string);

page.php?id=$sending_string.php

Now your string would be "This_is_my_string" which will pass find. Once your variable reaches the other page then reverse it to remove the underscore character and replace it with spaces:

$received_string = str_replace("_", " ", $id);

ahmedtheking

10:04 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah that's an idea! I'll try it out, thanks!

StupidScript

10:38 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) The max char count allowed in a URL is 255 characters, so any beyond that will be stripped off. You could build a hidden form using the POST method containing the dynamic values and submit the form to the opening page onclick where they would be accessible as part of the $_POST[] array.

i.e. (in the parent)

<form name="f1" action="child.php" method=post>

<input type="hidden" name="cssvalue1" value="<?=$dynamic_cssvalue1?>">

</form>

<a href="javascript:document.forms.f1.submit()">Child Page</a>

then in the child page:

<body bgcolor="<?=$_POST["cssvalue1"]?>">

2) Why not save the values to the parent page and then read those values from the child (pop-up), since you're using Javascript anyway?

i.e. (in the child)

cssvalue1=opener.cssvalue1;

document.bgColor=cssvalue1;

or some such ...

ahmedtheking

12:50 pm on May 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, yeah, but the problem wasn't the 255 url limit, it was the base64_encode!

Think of how long a normal css doc is, mine is about 250 lines long!

I've encoded strings that had spaces in them before with no difficulty!

I had a look at the mcrypt function and saw that it could condense a string into 2 chars! I also had a look at the php built in crypt function, but it wouldnt work!

In the end, I just decided to include the css parse script in the pop up window!

But i also tried having a css file created on the fly, eg

<link href="styles.css.php?id=style1" rel="stylesheet" />

But that didn't work! is there another way to incorparate such php/css stuffs or will i have to create different files?

PS thanks for all the help!

StupidScript

4:31 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whenever I need to load different style sheets depending on user choice or browser, I (1) detect/collect the determining factors and (2) load a stylesheet named for the purpose, i.e.

<link href="styles.css.php?id=style1" rel="stylesheet" />

becomes

<link href="<?=$thisStyle?>_style.css" rel="stylesheet" />

where

$thisStyle
holds the value of the determination (like "ie_style.css" or "blue_style.css")

ahmedtheking

4:47 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah but i want the CSS style to be made on the fly.

StupidScript

6:06 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you mean?

<link href="styles.css.php?id=style1" rel="stylesheet" />

implies that you have a single stylesheet that responds to a simple parameter. How is that "on the fly"?

ahmedtheking

1:22 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That doesnt work! Because the CSS is linked, not being called!

bazzais

10:59 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Hi

Yes - but I think what he/she means is you can make a lbbrary of css's (unless of course you have an unlimitted amount of dis-simalarities then you can't account for them all) and call them into the page according to a smaller querystring.

see what we mean?