Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. okay well that problem is fixed, your current error is somewhere else.
  2. all of them. php doesn't recognize those. It recognizes ' or "
  3. umm....no. If you can't understand the concept of replacing magic quotes with real quotes, then maybe you should pick up another hobby.
  4. it's referring to the magic quotes you have in your syntax. replace them with " or '
  5. To be more specific, your 2st pattern expects your to find the literal "<a href" as the beginning of the substring. So if your href attributes are not the first in attribute in your link, the match will fail. I am assuming based on the context of your "before" and "after" that you probably have anchor tags that aren't actually url links and therefore want to exclude them by only looking for tags that have the href attribute. I'm not sure why you have an "a" at the closing of your link tags but assuming that is really supposed to be there, this should work: $pattern_strip_1= '~<a([^>]*)href([^>]*)a><br />~'; $replace_strip_1= '<li><a{$1}href{$2}a></li>'; this has a couple of additional optimizations: - Use negative character class instead of match-all with lazy quantifier. It is safer and more efficient. - You don't need to escape all that stuff, only the ones that are the same as your pattern delimiter or mean something special to the regex engine. The only thing you had in there that really needed escaping was the / because you used that as your delimiter. And to that, when you are working with html, it's a good idea to choose a delimiter that doesn't commonly show up in html (like ~) so that you don't have to make your pattern more confusing by having lots of escaped chars in it - It's always a good idea to wrap your captured vars ($1, $2, etc...) in {..} to avoid ambiguity. Basically it lets php know that you meant $1 not $1a, etc... - Even with this pattern, there are some assumptions made..for example: ----- It assumes there is no spacing between the anchor tag and the br tag, and on the same line. ----- It also assumes there is a space and a / in the br tag which is technically correct markup, but most browsers will recognize <br> or <br/> so this pattern doesn't account for that. ----- It assumes everything will be in lowercase. regex is case-sensitive unless you specify otherwise
  6. @MrAdam : Yes, using server-side scripting to input the variable would be the easiest thing. You could even get the URL easy enough from php when the user submits the form, without the hidden field at all. But since he's asking for apples, we can only assume he needs an apple, not an orange. He may not have access to the server-side scripting (and it may not even be php!).
  7. Okay so your main problem is that your input field is html and you are trying to put javascript in it. Well you can't mix it like that. You have to use javascript after the fact to grab the element by its id and assign a value to it. However, you will then run into a problem of making sure the element is actually loaded into the DOM before javascript tries to assign a value to it. If you have an existing framework on your page like jquery, you can do something like this (jquery example): <input type="hidden" name="page" id="page" value=""> <script type='text/javascript'> $(document).ready(function() { $('#page').value = window.location; }); </script> If you do not have jquery or similar framework, you can go here to see what kind of coding you have to do to make sure the document is ready for all browsers (lots more code - which is why using jquery or similar is great). A third option that I don't really recommend but it works is to wrap the assignment in a function that checks if it exists. If it does not, keep calling the function until it does: <input type="hidden" name="page" id="page" value=''/> <script type='text/javascript'> function setValue() { if (!document.getElementById('page')) { var t=setTimeout('setValue()',100); return false; } else { document.getElementById('page').value = window.location; return true; } } setValue(); </script> This isn't really advisable though because if for whatever reason it never gets loaded, the function never stops getting called.
  8. If your employer requires it, and they know you don't know it, make them pay for the certification training at Zend. Businesses do that sort of thing all the time.
  9. The only thing that really *counts* right now is traditional college. Take some Computer Science classes at your local college. But if you want to go the certification route, Zend Certification is probably the most *legit* there is right now.
  10. so just cut to the chase, have all your teeth removed and replaced with enamel.
  11. page1.php <?php session_start(); $_SESSION['someVar'] = 'this is a session variable'; $_SESSION['someArray'][] = 'this is a session array (element 0)'; $_SESSION['someArray'][] = 'this is a session array (element 1)'; $_SESSION['someArray'][] = 'this is a session array (element 2)'; echo "<a href = 'page2.php'>click to go to page 2</a>"; ?> page2.php <?php session_start(); echo $_SESSION['someVar'] . "<br/>"; foreach ($_SESSION['someArray'] as $value) { echo $value . "<br/>"; } In most cases, there are basically there are 2 things to note: 1) In order to make use of session variables (or arrays), you have to have session_start() on your page somewhere before actually using the var/array, and it also has to be put BEFORE any output (including any whitespace). 2) All session variables and arrays are contained within the $_SESSION super global array. So session variables/arrays are really just elements of the $_SESSION array. You can see it better by doing on page2.php <?php session_start(); echo "<pre>"; print_r($_SESSION); echo "</pre>"; ?>
  12. $id = $row['id']; or... just use $row['id'] as your variable since you only have 1 returned...
  13. Okay well the only thing I can really see wrong is for your first 2 links, the 2nd argument for window.open() has a space in it ("View rooms" and "Add rooms"). In IE, you can't have a space.
  14. instead of echoing or printing it out, store it in a variable or array and return the variable or array after the while loop.
  15. no, there is no native var dump for js (yeah I don't understand it either...) but a quick search will reveal plenty of functions that loop through and emulate it easy enough.
  16. make a normal link. style it to look like a button. Or wrap a link tag around an image, however you want the "button" to look. Put the javascript call in the onclick of the link.
  17. {...} is a range quantifier. Example: {n} n occurrences exactly {n,} At least n occurrences {,m} At most m occurrences {n,m} Between n and m occurrences What your pattern says is..."match exactly 7 of...." except you aren't actually matching for anything in that pattern. Please explain what it is you are actually trying to match.
  18. Hardest thing about coding for me is dealing with other web devs. Best case scenario is they are good but have their own style of doing things..which is mostly okay, as long as they know wtf they are doing. Worst case scenario (which I should really call average case scenario) is they have no business being a web developer in the first place...client too stingy to put real money into that sort of resource so I'm stuck dealing with c/p cowboys.
  19. oh mjdamato...no jquery?? you are missing out...I resisted for so long but when I finally picked it up...my only bitch about it is why oh why did I not pick it up sooner!
  20. please post the code that actually outputs the images, not just the images themselves (like the echo "...."; or whatever)
  21. look into preg_replace_callback. It can extract data and replace it with something else as it finds it, and you can supply a function to be called (passing the extracted info, returning what to replace) each iteration, so you can perform your calculations in the callback function (or call some other function that does it, w/e).
  22. It seems to be happening whenever I go there. I guess it keeps getting blinded by my pure awesomeness.
  23. ah sorry about that...yeah the mysql (no i) version doesn't require the connection resource as an argument. If you don't supply it, it uses the last connection opened by default
  24. it would help if you showed us HOW you were trying to use it...basically it's just a normal function where you pass the string to it and it returns the escaped string. Main thing about it is that you have to have a db connection open first, in order to use it, because it relies on settings in your db to properly escape stuff. But in general, you would use it as such: // connect to your db somewhere before this... $id = mysqli_real_escape_string($_GET['id']); $posts_by_city_sql = "SELECT id, city_id, title FROM postings WHERE city_id='$id'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); //$title = $_GET['title']; // mysql_real_escape_string($title); while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; }
×
×
  • 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.