Jump to content

dde

Members
  • Posts

    20
  • Joined

  • Last visited

dde's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Interesting webpage Jacques, I found this article on it regarding PDO (and more).
  2. Ch0cu3r, could you explain me what the question mark and the plus sign is for? php.net manual says: ? extends the meaning of (, also 0 or 1 quantifier, also makes greedy quantifiers lazy. +1 or more quantifier. I'm lost.
  3. As ginerjm posted PDO is an option as well. Personally I'm also new to mysqli so I'm learning it as we speak. Anyway here is some small example: Connecting to a database is almost the same instead of msql_connect, you will now use msqli_connect or new mysqli. Mysqli stands for mysql improved. /* connection is set in the $connection variable */ $connection = new mysqli($db_server, $db_user, $db_pass) or die(mysqli_error()); /* OR with mysqli_connect. Note that you either use msqli_connect or new mysqli */ $connection = mysqli_connect($db_server, $db_user, $db_pass) or die (mysqli_error()); /* We can now connect and select the database with */ mysqli_select_db($connection, $db_name) or die (mysqli_error()); /* We we can use the mysqli prepared or PDO to safely insert data in the database. */ /* We prepare the inserting statement."image_author, image_description and image_pathfile */ /* are the Database column names. */ $statement = $connection->prepare("INSERT INTO images (image_author, image_description, image_pathname) VALUES (?, ?, ?)"); /* We can now bind the values which are supposed to go into these */ /* colums, stated as questionmarks. using the bind_param function. */ /* We also declare whether the values are a double (d), string (s) */ /* int (i) or blob (b)or blob with the i, d, s or b at the start */ /* of the blind_param. */ $statement->bind_param("sss", $image_author, $image_description, $image_pathname); /* Now execute the prepared statement */ $statement->execute();
  4. I have also tried the following, but not sure what to do with the result. preg_match_all("/\[(.*?)\]/", $text, $matches); $array = array(); for($i=0; $i < count($matches[1]); $i++){ $split = explode(" ", $matches[1][$i]); foreach ($split as $value){ array_push($array, $value); } }
  5. I'm looking for a method to replace everything between brackets. The patterns that I'm looking for are defined: "/\[([2-9TJQKA][hdcs])\]/" The pattern inside the bracket could accur 2 or even 3 times inside the brackets. For example first occurance would be [Ac Kd], here I want to replace Ac into an imge and Kd too. Later in the text I will most of the time get 3 sets, instead of two: [Jc Td 9d]. The sets always consist of [2-9JQKA][hdcs] and also in this order. Another example: [2d 2s 2h], or [3s 4h 5c]. If I use the following function, it would not work optimally because some texts do contain some of those sets which should not be converted, ONLY the sets between the brackets: $haystack = setReplace($haystack); function setReplace($haystack) { $array = array("2s", "2h", "2d", "2c", "3s", "3h", "3d", "3c", "4s", "4h", "4d", "4c", "5s", "5h", "5d", "5c", "6s", "6h", "6d", "6c", "7s", "7h", "7d", "7c", "8s", "8h", "8d", "8c", "9s", "9h", "9d", "9c", "Ts", "Th", "Td", "Tc", "Js", "Jh", "Jd", "Jc", "Qs", "Qh", "Qd", "Qc", "Ks", "Kh", "Kd", "Kc", "As", "Ah", "Ad", "Ac"); for($i=0;$i < count($array);$i++) { $result = str_replace($array[$i], "<img src=\"/images/".$code[$i].".png\">",$haystack); } return $result; } Any ideas?
  6. I took the substr and strpos method. /* starting position of the text */ $startpos = 0; /* string to find */ $string = "string"; /* count the string length */ $addcount = strlen($string); /* find the position of the string in the user submitted haystack */ $stringpos = strpos($haystack, $string); /* specify the position to cut the haystack */ $endpos = $stringpos + $addcount; /* put the first portion of the haystack in a vriable to be printed out later */ $header = substr($text, $startpos, $endpos); /* I always use var_dump to check for my results */ var_dump($firstPortion); /* Next portion of the haystack to be cut */ $string = "string"; /* count the previous $header string length */ $addcount = strlen($firstPortion); /* find string position for second portion of haystack, starting where the previous cut ended (strlen($firstPortion)). */ $stringpos = strpos($text, $string); $stringpos = $stringpos - $endpos; /* put the second portion in a variable */ $secondPortion = substr($text, $addcount, $stringpos); /* check for results */ var_dump($secondPortion); Works fine, and as expected. I'm however not satisfied with the coding itself. Any ideas for shorter and more cleaner methods?
  7. So far I've been thinking about using strpos, to find the position to cut. Then use substr to cut it out and put that portion in a variable.
  8. I'd like to edit specific parts of a submitted text what is the best way to do this? For example I get the following text: [name country] is very cold this time of year. Because I like the cold I would love to live there [end of line 2] whole lot more text here until [name country] if this text here exists, blabla [but Germany] is blabla [end of line] in some cases some more text here [summary] bla bla The text in the brackets are words that I already know before it has been submitted. Getting the words out has been part of my previous script, using preg_match and put them in variables. I want to put the first portion of the text in a row, if 2nd, 3rd and 4th portion exist, put them in a row too. Any ideas? [edited] I prefer to have these portions cut out and put in a variable. So I end up having a few variables and can later echo that out in rows
  9. This is because the variable $mailtoname and $mailtoemail are blank. When you want to get the values of form values, you have to use $_POST. In your form this is also states as "method=post". To get values from a form, you have to send it to the receiving page, in this case it is "sendemailWithCC_BCC.php". On the receiving page use the $_POST variable to get the values from the form.To do this you use $_POST['name of form input'] In your case you use $mailtoname = $_POST['mailtoname']; To see if it works just use echo $_POST['mailtoname'];
  10. Where is this basicForm.php located? Are you running it on a server supporting php? The code itself is working. Note though that there is a typo <form name"form1" method="POST" action="basicForm.php"> This however is not the cause of your problem.
  11. dde

    Finding $x.xx/$x.xx

    preg_match("/[\$\€]\d+[.]\d+\/[\$\€]\d+[.]\d+/", $haystack, $matches); Matches €00.00/€00.00 as well as $00.00/$00.00.
  12. Okay I'm done with searching for answers, working on this preg_match for about 3 hours now. I'm looking for "($0.01/$0.02 USD)" in a string. The needle might be slighty different. Possible strings that I might look for is: (€xx.xx/€xx.xx EUR) where the EUR can be changed into USD, including its signs.
  13. It would not be possible to have patterns in an array?
  14. So far I got this, but when having lots of words, the code becomes too big. Is it possible to have the words in an array? if(preg_match("/java/", $text)) { $match = "java"; } elseif(preg_match("/PHP/", $text)) { $match = "PHP"; } elseif(preg_match("/html/", $text)) { $match = "html"; } else { $match = "unknown programming language"; } echo $match;
  15. I'm trying to preg_match $text for specific words, defined in an array. $text = "PHP is a programming language of choice"; $text = "This is a function written in a programming language called PHP."; $words = array("/java/", "/PHP/", "/html/"); for ($i = 0; $i < count($words); $i++) { preg_match($words[$i], $text, $matches); } The problem with tis is that it returns 3 arrays, of which only the second one is a match, and the other 2 arrays are empty. The result is that I get notice error on my echo page because the 1st and 3rd arrays are empty. if I want the text to be searched for the first matching result, whether it is java, PHP or html, then stop (if possible) and echo/return the result, how will I do that? Perhaps preg_match is not to be used here but instead something like substr?
×
×
  • 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.