-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
if your data is already in a string you don't need file at all. If $pizza is what you are saying has that data, then try $lines = explode("\n", $pizza); to get each line into an array. Then for each line, explode at the space.
-
The posix regex engine and syntax (what ereg_xxx uses) is generally thought to be simpler to use, but not offer you as much control over what gets matched and how. The pcre engine and syntax (what preg_xxx uses) is generally thought to have a higher learning curve, but the return on that is being able to write more complex patterns. Also, pcre is perl compatible (hence the engine name: Perl Compatible Regex Engine), meaning more pattern portability. Overall they mostly have the same syntax. There are some differences here and there, most of them are how things are matched though. Most of the time people generally don't care or need something complicated or portable enough to warrant having to pick one over the other. But what might be slightly more relevant for average joe user is that the posix functions (ereg_xxx) will no longer be part of php's core package as of php6, meaning, if you write your scripts using ereg_xxx functions and plan on having them around a long time, you're going to have to install a separate package when (if) you upgrade your php.
-
maybe you can first explode $text at \n to get your initial array that file() would have given you.
-
When don't you toot your horn At least I admit when I play off-key.
-
use file to put each line of the file into an array element. Use a foreach loop on that array. In the foreach loop, explode at the space. You might possibly have to use preg_split instead, using \s. Your number will be the 2nd element of the explode/preg_split.
-
The point of certificates and degrees and all those other pieces of paper you get from schools and colleges and companies is that employers can look at it and know someone out there who is well established vouches that you can do whatever that piece of paper says. I can make my own site and setup a test and at the end of it, hand out a certificate if someone passes my test. I can make the testing process no less secure than anybody else out there, etc.. but if nobody knows who I am, why should they care whether I back someone or not? It is not a matter of validity but a matter of reputability. The Zend certification is the most reputable certification out there right now, because the people who created php, also created Zend. Who can more reliably vouch that someone is good enough at php, than the people who wrote the language and are the ones most responsible for pushing it forward? That does not mean that the Zend certification is the only certificate out there, or that it is or will ever be the only reputable/recognized one. But it's all relative. Even the Zend certification doesn't mean a whole lot. Technology is constantly changing. Software is constantly changing. Procedures are constantly changing. Having a good paper trail to point to for potential employers and clients still trumps any certificate offered, when it comes to this stuff, unless you are looking for a more traditional job like Network Admin or something else that would expect real college time anyways. Going through the exams and getting yourself certified certainly won't hurt your chances of getting a job or clients. But as it stands right now, it simply doesn't mean a whole lot. Let me let you in on a secret: you will learn a lot more by getting involved in a learning community like phpfreaks than any certification out there. Helping out answering questions in the help forums gives you actual experience, not just reading theory from books. You put yourself in the position of figuring out how to solve something for yourself, instead of the person asking for help. This teaches you the detective skills you need for tracking down bugs, reading the finer print of the manuals, etc... The more you help, the more visible you become, not only to the community, but to everybody else. Here is part of my actual resume: That is a verifiable paper trail of real world problem solving and knowledge put to practical use that any potential client or employer can look at and see for themselves what I am capable of doing. You're damn right I have that on there. And how do I know that that's just as good as any certificate, if not better? I have no certifications in anything. Yet I get clients on a regular basis that come from here. People who I've helped on the forums come and ask me to do paid work from them. People see my freelance post in the freelance section and I stand out from the other people. I was approached by a pretty large company with a lot of big name clients a couple weeks ago that has contracted me to work x amount of hours a month for them. I even got a nifty title out of it: Implementation Analyst. Makes me sound vastly important, eh? Haha I know that's a lot of horn tooting but I'm just mentioning to point out that if you're goal is to gain credibility for potential clients/employers, just going around grabbing certificates might help, and it certainly won't hurt anything (except maybe your pocketbook), but in my experience, the best "college" you can go to is a decent learning community and making yourself a part of it.
-
it's because your (.+) is greedy. You have 2 bold tags in your string so the (.+) in between your first b tags is matching all the way to the last closing b tag. Make it non-greedy by doing this (.+?) for all of them. But also, you're going to run into problems later on if someone does this: [b][/b] with any of your tags, not just the b tags. I'm pointing out to you the lack of stuff between them. Your patterns will cause problems because the + expects at least one character. So use * instead of +. * is 0 or more chars. So overall, change all your (.+) to (.*?)
-
just fyi that regex will allow for any number of non-traditional names, such as... j-o-h-n -------------- ''''j''j'j''''''''''
-
you are missing delimiters and also you aren't properly escaping the brackets. $string .= preg_replace('~\[b\](.*?)\[/b\]~','<strong>$1</strong>',$code);
-
eh, you're right. I didn't know that. I assumed it was like the other braces/brackets.
-
You're going to have to be more specific. For instance, you can do this: /^[a-z][-.a-z\s]*$/i This will force at least 1 a-zA-Z at the beginning, and then 0 or more a-zA-Z - . or spaceTAB chars. So, someone can still do: a------ a...--- a..\s\s\s\s\s\s\s...---- You could change it to this: /^(?:[a-z][-.\s]?)+$/i This will make it to where it has to start with a-zA-Z, and anywhere afterwards, you can only have 1 -. or spaceTAB, but even then, stuff like this will be legal: a.a.a.b-c-d e f John.Smith is-a-r.e.t a-r.dlotsofrandomlettersherethereisnolimit So you need to be more specific. Minimum length? Maximum length? How many times allowed to have those special chars? There is no crystal ball inside the computer. It is not psychic. It does not know what your intentions are. Not even gonna bother addressing the rest of your fields, as it would just be the same song and dance as above.
-
You do have to escape them...{ and } are special chars in the regex. For instance, ~^\w{5,10}$~ // alphanumeric string 5 to 10 chars long edit: well, maybe not inside the neg char class, but outside, yes.
-
nrg_alpha I'm going to go out on a limb and assume that since this is for a template, that whatever is inbetween {...} is not going to be a { or } (in other words, those are the delimiters) so would be more efficient to just use my regex. Of course, you know what they say about assuming...
-
$letters['old'] = array('A','F'); $letters['new'] = array('B','G'); $myText = str_replace($letters['old'], $letters['new'], $myText);
-
Can you give actual examples of the context these things are in? I'm thinking it would be easier to just ~\{([^\}]+)\}~ and then explode at the dot.
-
are those the only things on the line?
-
echo $$Var1;
-
give examples of the formats you want to allow, min/max length, etc.... The error message in your code says alphabetic chars only so your pattern for that would be: /^[a-zA-Z]+$/
-
p.s.- your regex is going to allow people to enter in things like: symbols used in names in non-traditional manner -shadiadiph .shadiadiph 'shadiadiph ,shadiadiph shad\s\s\s\sdiph just symbols ,,,,--''..... ............. ------....... 1 or more whitespace or tab \s\s\s\s\s\s\s no length restriction, other than 1+ (which btw, you can change the * to + in your regex to remove that first condition) s sh sdlkadflaskdjfaslkjslkssssssssssssssssssssssssssssssssssssssssssssssslkjlkalasdfj,,,,,,,,---
-
my first guess would be that its actually failing because slashes aren't allowed, and slashes are being added to the apostrophe on form submit. echo $name out to confirm, and use stripslashes before the regex if so.
-
If you are wanting it to show tutor message if type==tutor, student message if type==student, and the links if it doesn't exist or if tutor==anything else, you can do this: <?php $type = $_GET['type']; switch($type) { case "tutor" : echo 'you have chosen tutor'; break; case "student" : echo 'you have chosen student'; break; default: echo '<a href="?type=tutor">TUTOR</a> or <a href="?type=student">STUDENT</a>'; } // end switch ?>
-
Your condition structure assumes that your GET var exists. It starts out by assuming that it exists but has a 0 length value. It only happens to work on first load because a variable that doesn't exist coincidentally happens to have a 0 length value. If the rest of your script is setup to always be passing that var via GET, and it's a matter of whether it's '' or something else, then your condition is okay. But if its not, consider using isset You also have it setup to where if $_GET['type'] exists and is anything other than '' or 'tutor', then it must be a student. So if I were to enter this into the url: http://www.yoursite.com/yourscript.com?type=somerandomvalue your student message will appear. If that is your intention, then sure, you're good to go.
-
No, you cannot use an array for patterns with preg_match. You can only do that with preg_replace. If you have multiple patterns you want to match, you need to loop through your array.
-
uasort sorts things based on a user defined comparison. It's not php's fault the numbers don't sort the way you want them. It's yours. Post your code, post an example list of stuff to sort, and example of what you want the result to look like and why it's supposed to be sorted like that.
-
So...you're saying that the file IS there, but php is saying it's not, but it IS being deleted anyway? Are you sure it was there in the first place? Or perhaps your code is being executed twice.