PHP - Rainbow Text Function: Ignore Html
Hello there,
I am working on a script that will take a user submitted text and display the text in rainbow. I found a very nice function on the Internet and used it as my base. Here is an example of the code. Code: [Select] function rainbow($text) { /*** initialize the return string ***/ $ret = ''; /*** an array of colors ***/ $colors = array( 'ff00ff', 'ff00cc', 'ff0099', 'ff0066', 'ff0033', 'ff0000', 'ff3300', 'ff6600', 'ff9900', 'ffcc00', 'ffff00', 'ccff00', '99ff00', '66ff00', '33ff00', '00ff00', '00ff33', '00ff66', '00ff99', '00ffcc', '00ffff', '00ccff', '0099ff', '0066ff', '0033ff', '0000ff', '3300ff', '6600ff', '9900ff', 'cc00ff'); /*** a counter ***/ $i = 0; /*** get the length of the text ***/ $textlength = strlen($text); /*** loop over the text ***/ while($i<=$textlength) { /*** loop through the colors ***/ foreach($colors as $value) { if ($text[$i] != "") { $ret .= '<span style="color:#'.$value.';">'.$text[$i]."</span>"; } $i++; } } /*** return the highlighted string ***/ return $ret; } $post[message] = rainbow($post[message]); And it works very well Here is my problem. At times $post[message] will contain some basic html such as a bold tag, user smiley (img tag), a link tag, and so forth. How can I take my function above so that it doesn't edit and add the html font color coding for anything inside html tags where it just skips over them and leaves that part alone? I need this otherwise it will breakup every html tag I might have inside $post[message] and add a font color html tag to it, thus voiding all other html in it. Similar TutorialsI apologize in advance, I know pretty much nothing about PHP - don't hate me, please! But I'm working on a form mailer, and it functions, but what I don't like is it leaves all the text fields, blank or not, in my email, which makes it difficult for my client to read, so theres a long list of txt field1: another text field: blah blah: all the way down the email - and I want it gone! haha. I've researched how to do this, but basically, I have no idea how to implement it into my code and don't have time right now to up and learn PHP. My code is as follows: Code: [Select] <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> IT was a very simple copy-paste form, but I have no idea what on earth I'm doing. If anyone has any ideas I would GREATLY appriciate the help! Thanks! -Austin I know your going to say google it, and I did but I couldn't find a ENGLISH definition lol for someone who's clueless with how encryption work. What are rainbow tables, and what is salting. Also, how does salting prevent rainbow table attacks? Hi all, I have a simple html form, when the values are posted to the php page I want to be able to bring up particular products based on specific details. However if the user does not enter a value, I want the script below to ignore that particular field and show all the results not taking in to consideration that field. Hope you understand. I was thinking maybe I could use something like if $_POST == "" IGNORE!! but I can not find an example on the internet. The script I have made so far is below. <?php $sql = "SELECT * FROM sales WHERE category='$_POST[category]' AND manufacturer='$_POST[manufacturer]' AND model='$_POST[model]' AND purchasetype='$_POST[type]'"; // IF VALUE OF SAY MODEL IS LEFT BLANK - I WANT THE PHP TO INGORE THE TYPE OF MODEL AND SHOW THE RESULTS JUST INCLUDING THE OTHER FIELDS. $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Login Name found { while($row = mysqli_fetch_assoc($result)) { ?> How can I ignore - when doing claculations? e.g. 150 - 50 = 100 150 - 225 = -75 // I WANT to display only 75 and ignore the - sign I have the following Query: Code: [Select] $query = "INSERT INTO characters SET psalt = '" .$salt. "'"; However, when the salt is generated, it may contain a ', thus stopping the Query. I need to know how I could make it so the Query would be unaffected by the ' in the salt value. Thanks! i have a script that calls for a field, but if you arent on a blackberry it asks you to select a name first, so it gives error until you select: Notice: Undefined variable: posteid in E:\Website\citycore\2\mobile\schedule.php on line 20 i could make it so it didnt call for $posteid until after the name is selected, but then it wont work from the blackberry as it detects the pin number first. EDIT: I solved it! im trying to insert $myusername into a table only if $myusername does not exist is best to call the insert ignore or is there better way of doing this? also trying to make a list of logged in users which is allways updating when the page is auto refreshed whats the best to go about checking if the users is still there. I have a pspell script and I want it to ignore upper case. ie at the moment if I check spelling for say christopher it returns spelling error of Christopher (upper case C) <?php $query = 'helllo'; $pspell_config = pspell_config_create("en"); pspell_config_ignore($pspell_config, 5); pspell_config_mode($pspell_config, PSPELL_FAST); pspell_config_personal($pspell_config, "/home/*/public_html/custom.pws"); pspell_config_repl($pspell_config, "/home/*/public_html/custom.repl"); $pspell_link = pspell_new_config($pspell_config); $words = preg_split ("/\s+/", $query); $ii = count($words); global $spellchecked; $spellchecked = ""; for($i=0;$i<$ii;$i++){ if (pspell_check($pspell_link, $words[$i])) { $spellchecked .= $words[$i]." "; } else { $erroneous = "yes"; $suggestions = pspell_suggest($pspell_link, $words[$i]); $spellchecked .= $suggestions[0]." "; } } if($erroneous == "yes") { $spellchecked2 = str_replace(" ", "+", $spellchecked); echo "Did you mean: <a href=GetSearchResults.php?Query=$spellchecked2&catID=&siteID=3><i>".$spellchecked."</a></i>?"; } else { echo $spellchecked . " is a valid word/phrase"; } ?> ignore Having a problem with that "insert ignore into". If it is a new record, it works, when it is a excisting record that needs to be updated, it is giving me this error: Cannot execute query: INSERT IGNORE INTO (gedcom,kennel) VALUES ("World","Avongara") What or where is it going wrong? This message is for me not enough to find the problem. $kennels = array(); if( !in_array( $kennel, $kennels ) ) array_push( $kennels, $kennel ); foreach( $kennels as $kennel ) { $query = "INSERT IGNORE INTO $kennels_table (gedcom,kennel) VALUES (\"$tree\",\"$kennel\")"; $result = @mysql_query( $query ) or die ("$admtext[cannotexecutequery]: $query"); } Thanks for helping Below is some code I have that I would like to connect to databases that reside on different physical machines. The problem I can't seem to solve is how to ignore machines that are unreachable. Code: [Select] <html> <head> </head> <body> <?php $mysql_conn=new mysqli('192.168.1.67','admin','password','monkey'); $result=$mysql_conn->query("SELECT * from testtable"); echo "<table>"; echo "<th>Test Query</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['test1']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.126','admin','','monkey1'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.127','admin','','monkey2'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['processor']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> If 192.168.1.126 is offline, the webpage doesn't go any further and display 192.168.1.127's info...Appreciate any insight... I want half of the results to to show up with a hyperlink (if I've added the link as a field in my CSV file) and half of the results to show up with no hyperlink. The link URL's are located in field 8 of a database : [8] as seen below. Could anyone help me to figure out how to add an "if" statement perhaps? Something like "if 8 true" then display "<a href"? I did not write this php code I am only modifying it. The csv file is very very straightforward, but this PHP is beyond me. Would appreciate the help! <p><a href="<?=htmlspecialchars($r[8])?>"><?=htmlspecialchars($r[1])?></a><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309981.0 Hi I'm currently experiencing a problem with my query. I've used the `INSERT IGNORE` option in my query and it works pretty well not to add duplicates, but the problem is that if my unique field match it doesn't update any other info in the row, is there maybe another option to update a row if an existing field exists but insert new row if it doesn't exists?
my current query is as follow
$query = mysqli_query($con,"INSERT IGNORE INTO mxit (ip,time,user_agent,contact,userid,id,login,nick,location,profile) VALUES ('$ip','$post_time','$mxitua','$mxitcont','$mxituid','$mxitid','$mxitlogin','$mxitnick','$mxitloc','$mxitprof')") or die(mysqli_error($con)); I am working on a little project for my site and I am trying to get this script to ignore the index.html file and the .htaccess file in there. I just want it to display all files like .zip, .rar, .tar, .gz, .gtar, .ace, ect... echo " <td width='70%'><select id='download'>"; echo " <option value=''>None</option>"; if ($handle = opendir("./modules/Downloads/files")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo " <option value='".$file."'>".$file."</option>"; } } closedir($handle); } echo " </td>\n"; hello guys
i have 2 time variables
$time1 = 22:00;
$time2 = 03:00;
my $current_time is 01:00
how can i figure that $current_time is betwean the $time1 and $time2
the
if ($current_time > $time1 && $current_time < $time2)
works if the day not change!
is any way to ignore the day change
thanks
Edited by lioslios, 09 November 2014 - 10:07 PM. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345658.0 Aloha, I am using a simple html form and php script to send data to a SMS gateway that I have setup already. Everything works great. I fill out the form, the data is sent and instantly I get a text message on my iphone. Here's the problem. If I use an apostrophe in the message text field I get an error code. I am assuming the html text field needed to be escaped but I tried everything and I still get the error. Any ideas on what to check or do? Here's the php send code (variables coming in from html form fields): Code: [Select] <?php if (!empty($_POST)) { $name = trim($_POST["name"]); $contactnumber = trim($_POST["contactnumber"]); $message = trim($_message); if (empty($name)) { exit("Name cannot be blank."); } if (empty($contactnumber)) { exit("Please provide a contact number."); } if (empty($message)) { exit("Message cannot be blank."); } $subject = "$name . $contactnumber"; $strlen_subject = ($subject != "") ? strlen($subject) + 3 : 0; $strlen_message = strlen($message); $express = $_POST["express"]; if ($express && ($strlen_subject + $strlen_message > 160)) { exit("In case of express delivery, message length should not exceed 160 characters."); } elseif ($strlen_subject + $strlen_message > 130) { exit("In case of standard delivery, message length should not exceed 130 characters."); } $subject = urlencode($subject); $contactnumber = urlencode($contactnumber); $message = urlencode($message); $ch=curl_init('https://app.eztexting.com/api/sending'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,"user=PuaDog&pass=808cougar&phonenumber=18087211458&subject=$subject&message=$message&express=1"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $data = curl_exec($ch); switch($data) { case 1: header('location:message_sent.php?message1=1'); break; case -1: print("Invalid user or password"); break; case -2: print("Credit Limit Reached"); break; case -5: print("Local Opt Out"); break; case -7: print("Invalid Message"); break; case -104: print("Globally Opted Out Phone Number"); break; case -106: print("Incorrectly Formatted Phone Number"); break; case -10: print("Unknown Error"); break; } } ?> Mahalo! Tom MOD Edit: [code] . . . [/code] tags added . . . Kindly let me know how can i assign values to a php function from any textbox when user clicks on the submit button??? Code: [Select] <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> <input type="submit" /> </form> |