Jump to content

carlos1234

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

carlos1234's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks very much for taking the trouble of figuring that out Alex. Much, much appreciated. I thought of doing that myself (in theory) but I am actually after just a standard regexp that might do the trick. We'll see if anyone else can come up with such. If not I will probably use your solution. Thanks again Alex! Carlos
  2. Thanks Alex but I need the entire path minus the last "swme-". Too complicated to explain why here but it's part of a CMS system I am creating and I need the full path and base file name to remain. I mean I could use your approach, strip out the "swme-" from the file name, and then put it all back together again but that seems like a lot of trouble to go through given that there is probably a simple regexp that will accomplish what I want and that I am hoping someone here will point me to. Carlos
  3. Thanks for moving this to the correct forum Alex. I had forgotten there was a regexp forum here when I posted it and then couldn't firgure out how to move it myself. I kinda solved my problem by using the following revised preg_match but it's not really a solution since it limits my file names to only the characters in the character class involved...which is not really disireable. preg_match('/\/swme-([a-z0-9-]*?\.txt)/U', $string) That will return the string I want when I apply a preg_replace using the same regexp in it. preg_replace('/\/swme-([a-z0-9-]*?\.txt)/U', '/$1', $string) returns "/home/carlos/web/swme-site-generator/contact-me.txt" which is what I am after. In other words I am looking at removing the last occurance of "swme-". But now I am stuck having to remember where this regexp is in the code so as to change it every time I want to allow a new character into file names. Not good. There must be a more elegant and generic way to remove the last occurance of "swme-" from the string in question. Anybody? Carlos
  4. I'e been Googling and Googling and reading and reading to no avail and would really appreciate any input anyone might have on how I can match the last occurence of "swme-" in the following string (this is one of those times when Google is near useless at least with respect to returning any relevant pages). $string = "/home/carlos/web/swme-site-generator/swme-contact-me.txt" The preg_match I have been trying to work with doesn't work yet. It's... preg_match('/\/swme-(.*?\.txt)/U', $string) The problem is that the regex matches "/swme-site-generator/swme-contact-me.txt" and not "/swme-contact-me.txt". I thought that using the '?' would keep it from being greedy but I guess not. Anybody got any ideas on how to match only the last bit of the string where "swme-" is found? I am trying to remove the last "swme-" from the string. Thanks. Carlos
  5. Thanks rarebit but I am still unclear. I understand that the server receives stuff and then hands it over to the PHP interpreter for handling. In my case all files ending in .php. What I am unclear on is whether the array construct that you see in my HTML form is a capability of HTML itself or whether the array constructs in the form I posted only work because PHP reads the HTML and processes them as arrays? In other words does the HTML have an ability to return POST variables of an array kind irrespective of whether an HTML form is processed through PHP, Perl, or any other scripting language or is it a matter of a scripting language reading it as such but where HTML itself does not allow array constructs by itself. If I had the time I would see if the same thing could be possible with Perl but I haven't fooled with Perl in a long, long time. I hope my question makes sense. Carlos
  6. I just discovered today that I can apparently create arrays in my HTML forms but I have not seen official documentation on this anywhere and am wondering if this feature is a PHP capability (where PHP parses the HTML in the .php file and renders the array constructs into arrays) or whether the capability in question is a feature of just HTML (irrespective of what PHP does with it). Here is some code that shows what I am asking about... <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo "<pre>"; print_r($_POST); echo "</pre"; } ?> <form action="" method="POST"> <input type="submit" name="submit" value="Submit"> <br> <input type="text" name="field_set[1][sort]" value="1"> <input type="text" name="field_set[1][link_text]" value="About Me"> <input type="text" name="field_set[1][link_points_to]" value="about-me.txt"> <input type="text" name="field_set[2][sort]" value="2"> <input type="text" name="field_set[2][link_text]" value="Home"> <input type="text" name="field_set[2][link_points_to]" value="home.txt"> <input type="text" name="field_set[3][sort]" value="3"> <input type="text" name="field_set[3][link_text]" value="Privacy Policy"> <input type="text" name="field_set[3][link_points_to]" value="privacy-policy.txt"> </form> The output looks like this... Array ( [submit] => Submit [field_set] => Array ( [1] => Array ( [sort] => 1 [link_text] => About Me [link_points_to] => about-me.txt ) [2] => Array ( [sort] => 2 [link_text] => Home [link_points_to] => home.txt ) [3] => Array ( [sort] => 3 [link_text] => Privacy Policy [link_points_to] => privacy-policy.txt ) ) ) Anybody? Thanks. Carlos
  7. I just discovered one difference between my local install and the hosted Apache install. On the hosted server the ownership of the public_html directory is user:carlos and group:nobody. Locally it is user:carlos and group:carlos So obviously the group on the hosted Apache (i.e. nobody) has write permissions to the document root that the group locally (i.e. carlos) does not. Hmm...now I have figure out how to tell what permissions the group, carlos, how to change them, and whether I am even should. Carlos
  8. I am trying to duplicate a functionality on my hosted server locally, so that I can develop sites locally under my own copy of Apache, but I am running into a problem that is a showstopper and that I can't yet get around. Here is test php file. <?php if (file_put_contents("junk.txt", "Hi there. I am inside of junk.txt!")) { echo "File was WRITTEN to disk!"; } else { echo "File was unable to be written!"; } ?> When I run the above file under my local copy of Apache (running as user www-data) the above script fails to write the file junk.txt. When I run it at my hosted server...no problem. It writes the file just fine. Locally when I "touch junk.txt" from a command line the junk.txt file is created with a permission of -rw-r--r-- (I don't know what the corresponding number of that chmod is). Same thing on the hosted server. If I create the file locally and change the permissions to -rw-rw-rw-, no problem. But I don't need to first create the file and change it's permissions on the hosted server to successfully run this script and needless to say having to create files first and open up the permissions somewhat locally every time my scripts want to create a file just won't cut it. The directory permissions of both document root directories is also the same and are both set at drwxr-x--- How can I get around this obstacle and make my local Apache able to write files like it can on the hosted server? Any help on this would be appreciated. Thanks. Carlos
  9. Sure enough...after playing around with it for a few more hours and slowly building up a test form one item at a time to observe the effect it came down to resetting things across the browsers. Thanks very much for the input!! Your all's input allowed me to save some hair instead of pulling it all out (in a manner of speaking of course). It gave me hope that there was a solution. The problem I was having is that I had headings on top of HTML input boxes. The input boxes themselves were in a slightly different but barely noticeable at that, font. I couldn't for the life of me figure out why the headings kept going out of whack depending on the browser I was looking at things through until I explicitly set the input font and other characteristics to be the same as the heading text had. That's when they finally lined up nicely! Thanks again! Carlos
  10. Hmm....I'll have to take a second and closer look at your code Zanus. Maybe you came up with a solution that was so...well...elegant that it flew over my head . Thanks for going through the trouble of explaining your solution more. I will see about getting back to this later today. I have so much on my plate this morning that I just can't get to it right away. Carlos
  11. Thanks Zanus but it does not seem that your solution will do what I need. You see $k is not consistent as the right key between $userArray and $defaultArray as your solution supposes it is. $userArray has additional keys (with their corresponding values) more than $defaultArray. In other words every key in $defaultArray is also found in $userArray but $userArray has addtional keys not found in $defaultArray. What I originally had been trying to do was insert the extra keys from $userArray into $combinedArray just below the key in $defaultArray that it was related to. Let me give an example... $userArray keys and values: PageBackgroundImage= PageBackgroundImageUsed=yes ContentBackgroundImage=images/new-background.png ContentBackgroundImageUsed=no $defaultArray key and values: PageBackgroundImage=images/page-background.png ContentBackgroundImage=images/content-background.png What I would want to end up in $combinedArray would be: PageBackgroundImage=images/page-background.png PageBackgroundImageUsed=yes ContentBackgroundImage=images/new-background.png ContentBackgroundImageUsed=no Settings in $userArray take precedence over any settings in $defaultArray. Notice how the appropriate ....Used setting is inserted below the one that it applies to? That is what I originally had in mind and did with my code. I am going to flag this as solved for my purposes at this point since it does not seem that there is any really more efficient way to do this other than what has been proposed in the thread so far. Thanks again for the input you all. Much appreciated! Carlos
  12. Thanks again Mike but my arrays won't ever be bigger than about 50 settings if that. So speed wise like you said...it won't make any bit of difference at least respecting anything that would be visible by the naked eye. I like your sorting idea except that my settings are grouped together and are not in alphabetical order in the ini files. But the internal ordering of the elements in the arrays that these settings are read into is only useful for me in debugging things. Once things are fully debugged the internal order of what is read into the arrays won't make any difference at all. Thanks again Mike. Carlos
  13. Hmm...interesting solution you have there Mike. Very good! I will have to toy around with that some. Don't know if it's faster but then again my code operates fast enough so I am sure your solution will be more than adequate. It's certainly cleaner looking. The only "problem" which is really not a problem is that the keys will not be in the same order more or less as the order that they are found in inside the respective user and default setting files. But really the order of the keys in the arrays is only good for debugging. Once the code works flawlessly it won't matter what order the keys are in. Thanks for the tip! Carlos
  14. Yes...using a database is out of the question. I am developing a simplified web site creation system that involves reading a userSetting and defaultSetting ini files for it's settings. The system does not use the overhead of a database on purpose since it is meant to be lean and mean for the purpose of creating simple web sites like the kind that one needs to create for Adsense. Even if I stored the values of userSettings and defaultSettings in a database it would not alleviate me of having to figure out how to combine their values on the fly. Since my system accepts as input only one set of settings that are then used as the active settings to use. The code I posted works but I am just wondering if there is a more efficient way to do it. Actually I had to fix something in the code...the code below is what actually works as intended. while (list($userKey, $userValue) = each($userSettings)) { while ($defaultKey = key($defaultSettings)) { $defaultValue = current($defaultSettings); if ($userKey === $defaultKey) { if ($userValue === "") { $combinedSettings[$defaultKey] = $defaultValue; } else { $combinedSettings[$userKey] = $userValue; } next($defaultSettings); // to allow key() to work properly above. } else { // leave defaultSettings where it is but collect the right key/value into // combinedSettings array. if ($userValue === "") { $combinedSettings[$defaultKey] = $defaultValue; } else { $combinedSettings[$userKey] = $userValue; } } break; } } Carlos
  15. array_merge() definitely does not do what I need Mark. It always takes the value of the second array when merging if the two keys are the same. For my needs $userSettings (the first array) always has precedence in the merge unless it is blank in which case I take the value in the same key in the $defaultSettings array. array_match() also appends new keys and their values to the end of the combined array which I do not want. I want keys to be inserted in their proper place in the order of keys. Thanks for the suggestion though. Carlos
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.