Jump to content

carlos1234

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by carlos1234

  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
  16. I have three associative arrays. $combinedSettings $userSettings $defaultSettings My function must combine the key and value from $userSettings and $defaultSettings into the $combinedSettings array. $userSettings will always contain more keys than $defaultSettings will ever have. So every once in a while there is an extra key and of course it's value in the $userSettings array than in the $defaultSettings array. If the value of a key in $userSettings is empty we then use the value for the same key in the $defaultSettings. Every key in $defaultSettings will always be present in $userSettings. $userSettings just adds a few extra keys and their values. Below is my working code but I am wondering if there is some way to make it more efficient, faster, perhaps with less code. It looks rather clutzy to me. Rather bloated. while (list($userKey, $userValue) = each($userSettings)) { while ($defaultKey = key($defaultSettings)) { $defaultValue = current($defaultSettings); if ($userKey === $defaultKey) { if ($userValue === "") { $combinedSettings[$defaultKey] = $defaultValue; } else { $combinedSettings[$userKey] = $userKey; } next($defaultSettings); // to allow key() to work properly above. } else { // add userSettings setting and value to combinedSettings and leave // defaultSettings where it is. $combinedSettings[$userKey] = $userValue; } break; } } Thanks. Carlos
  17. Hmm...interesting. Yes I can see that now but the documentation mentions "//1" (the old style backreferencing)...not $1 (the new style). I don't think I would have made the connection between that old style and new style and figured out that the problem was related to that on my own without your all's help. But thanks for pointing that out though. Appreciate it. Carlos
  18. I haven't tried the solution proposed yet but it makes sense and I am excited to implement it! You all rock! I wouldn't have figured out what you all said in a million years of Googling everything I could get my hands on regarding regular expressions. Thank so much again!! Carlos
  19. Thanks for the input. I don't believe I have tried a full reset yet but from what I have tried in setting margins and padding to 0 I don't think that's going to solve the problem. I use em's throughout. An em is the distance equal to the text size. But since each browser renders an em of 1 for example at a different visual text size I think the difference in width when set through em is going to remain. Because the font size, even if set to the same em, is slightly different across browsers. I will have to try setting widths with just pixels but I think I tried that and it didn't work either. I'll see if I can whip up some CSS HTML code to better explain and show the problem I am having. Thanks. Carlos
  20. I am creating a great big form for an application I am building (it's quite messy so I won't be showing it until I at least clean it up some LOL) but I have having a real problem lining up the columns in the form. There are multiple rows and multiple colums in each row. Just like the good ol table structure that I used to use and which was no problem. The problem using CSS is that whatever width I make the columns (i.e. using px, em, or percentages) each browser treats these measures differently. Not a whole lot different but enough to where columns may line up real nicely in IE and then be misaligned in Firefox. Short of having different CSS for each browser is there a way to line up columns created with CSS?? If I was using a table no big deal. Whatever I would put inside the table TD columns would stay lined up across browsers. Any input would be appreciated. Thanks. Carlos
  21. Thanks very much for the input. Not sure if preg_replace really gets confused as you say though I did figure out that if I put a space or any other character between the $2 and $newvalue that it works as it should. Is there no other way to just use a regexp in preg_replace without having to work around preg_replace's "confusion" as you mentioned? Carlos
  22. I have been going round and round on this for a couple of days and just can't figure it out. Would appreciate any insight anyone might have as to why this is happening. What I am trying to do... I want to replace the value of a setting found on the right hand side of the equal sign in the $text variable below. Instead of the value being 6 spaces followed by "16em" I want it to end up being 6 spaces followed by "24em". Instead I end up with space followed by "4em". Why? The preg_match seems to work just fine. Here is my test code... <?php $text = "LeftWidth = 16em\n"; preg_match('/([a-zA-Z]*)\s*=(\s*?)([ a-zA-Z0-9]*)\n/U' , $text, $matches); echo "\$matches[0] = [$matches[0]]<br>"; echo "\$matches[1] = [$matches[1]]<br>"; echo "\$matches[2] = [$matches[2]]<br>"; echo "\$matches[3] = [$matches[3]]<br>"; $newvalue = "24em"; $text = preg_replace('/([a-zA-Z]*)\s*=(\s*?)([ a-zA-Z0-9]*)\n/U', "$1=$2$newvalue\n", $text); echo "[$text]<br>"; ?> Any input would be greatly appreciated. Thanks. Carlos
  23. If you create a DATETIME file in a mysql table it is my understanding that this field is automatically updated whenever a change is made to the record that contains that field. So really, if that is the case...you do not need a PHP function to give you the proper date and time. Just create a field and make it of type DATETIME and then make a chance to the record and see if that field is updated automatically. Carlos
  24. Yeah...I nearly always check the source code of what is output. With the exception of when trying to debug things. When I am debugging...I just rely on the output as it appears on the screen of my browser. This is actually the first time I encountered this kind of quirk and it had me completely, 100% stumped. I kept looking and looking at the output, changing the code a bit here and there, looking and looking and just could not for the life of me figure out why part of the string I was trying to output kept disappearing on me. Thanks again! You bad (sorry I couldn't help it LOL)! 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.