PHP - Issue In Coding When Using Substr Function
Hi,
When i am getting the part of the text using the function substr, am getting this kind of problem , (text in the end not printing properly) how to solve this. تسر مؤسسة مهارات التقنية ومؤسسة اشبكة الثنائية ان تطلع جميع عملاءها بإصدار نظام تاتش لإدارة الموقع الالكترونية من يوم السبت ا� This is the code am using $sub_string_content = substr($temp['News_Content'],0,300); Thanks, Similar TutorialsIm new to PHP so bare with me. I created a form for my website. A person can enter the information and when they hit "submit" all of the information is sent to my email. for example:
name: mike
state: ca
comment: hi
my problem is this: some of the entered information is sent, while other entered information is not. I also have a drop down menu that the user can chose from a variety of answers. how do i use php to get that information sent to my email? If this isnt a clear explanation please forgive me b/c Im not so sure how to explain it.
Any help is appreciated!
Hi ; Im getting the below error from Access database please help me to fix it. [root@db_cesar home]# php test.php table name : t_b_Door column name : f_DoorID t is not a table in this database Error at Line : syntax error near _ PHP Warning: odbc_exec(): SQL error: [unixODBC]Couldn't parse SQL , SQL state 08001 in SQLExecDirect in /home/test.php on line 15 This is my code <?php $conn=odbc_connect("logindb","",""); if (!$conn) { exit("Connection Failed: " . $conn); } $sql="SELECT f_ReaderID FROM t_b_Reader"; $rs=odbc_exec($conn,$sql); if (!$rs) { exit("Error in SQL"); } while (odbc_fetch_row($rs)) { $f_ReaderID=odbc_result($rs,$f_ReaderID); //$conname=odbc_result($rs,"ContactName"); echo "$f_ReaderID \n"; } odbc_close($conn); ?> Thanks Hello, there I'm new at the PHP/MySql matter and so the code I'm going to bring up that I'm having trouble with was written by someone else for me a number of years ago. It worked just fine until recently and I'm not sure why it just up and stopped working. Nothing has changed, the database that this code is connected to is still very much the same. The problem I am having is trying to login via the Login name and Password. As I said before this code worked just fine up to a few days ago and the person that wrote this out for me has long since disappeared into the ether and I would really love to get this back up and working again, I just don't know where to begin. Now the problem, once from the login it gets me far enough to the "Login Success. Forwarding to tools..." that takes all who have access to tools to this next stage and that's when the trouble hit, with the information in and it sits and then come back "No password provided" so its basically not gettting the information from the database itself. Or something. So yes, if someone see something small, or an update in code or something, would be great. Otherwise... just have to give up on this. Be my luck the other PHP code that I have for the other various things - I run an online Roleplaying site requires people to submit character sheets, then to be able to view sheets, edit certain part of the sheets and this particular project is for the Storytellers to update those sheets - has decided to say um, I'm done working now. My webprovider offers the following if this is needed information wise: MySQL version 5.0.90-community PHP version 5.2.13 Thanks much for taking the moment to look this over, I'll try to provide as much detail I can if anyone post any further inquiry on this odd problem of mines. <?PHP if( !isset($pass) ){ die("No password provided"); } if( $pass == "" ){ die("No password provided"); } $sql = "SELECT * FROM stlogin WHERE id='$ID'"; mysql_connect("localhost", "USERNAME", "PASSWORD"); $rs = mysql_db_query("primevil_database",$sql); while ($row = mysql_fetch_object($rs)){ $password1 = $row->pass; $login = $row->login; $access = $row->access; } if( $password1 == $pass ){ } else{ die("Password not matched"); } ?> <?PHP if($access >= 2){ echo "Welcome $login. <BR>"; } if($access == 3){ echo "<strong><font color=\"#FF0000\">ST Level Access</font></strong><BR>"; } if($access == 2){ echo "<strong><font color=\"#FF0000\">Assistant ST Level Access</font></strong><BR>"; } if($access == 4){ echo "<strong><font color=\"#FF0000\">Admin Level Access</font></strong><BR><a href=\"deletechar.php?ID=$ID&pass=$pass\">Delete Character.</a><br>"; } if($access == 3 | $access == 4){ echo "<a href=\"editchar.php?ID=$ID&pass=$pass\">Edit Character.</a><br>"; } if($access == 2 | $access == 3 | $access == 4){ echo "<a href=\"searchchar.php?ID=$ID&pass=$pass\">Search Character.</a><br><a href=\"viewchar.php?ID=$ID&pass=$pass\">View Character.</a>"; } ?> I'm using a wordpress theme which comes with a zoom feature for the product (main image and image gallery thumbnails). It currently opens the primary image (and any thumbnail) in a modal window which is quite ugly for a product showcase. Code is: Code: [Select] $imgtag = '<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' />'; if (value_is_true($zoom)) return '<a href="'.ecarturl($img->id,'images').'/'.$img->filename.'" class="'.$zoomfx.'" rel="product-'.$this->id.'">'.$imgtag.'</a>'; I'm trying to implement Cloudzoom (http://www.professorcloud.com/mainsite/cloud-zoom-integration.htm) I changed the code to: Code: [Select] $imgtag = '<a href="'.ecarturl($img->id,'images').'/'.$img->filename.'" class = "cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:\'inside\'"> <img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' /></a>'; if (value_is_true($zoom)) return '<a href="'.ecarturl($img->id,'images').'/'.$img->filename.'" class="cloud-zoom-gallery" rel="useZoom: \'zoom1\'">"'.$imgtag.'</a>'; HTML Output: Code: [Select] <div id="main-picture-default"> <a href="http://www.url.com?siid=9/2-9202.jpg" class = "cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:'inside'"> <img src="http://www.url.com?siid=9&360,450,1,100,2441305929" alt="product-picture" width="360" height="450" /></a> </div> <div id="thumbs"> <ul id="thumbs-list-default"> <li class="one_third "><a href="http://www.url.com?siid=9/2-9202.jpg" class="cloud-zoom-gallery" rel="useZoom: 'zoom1'">“<a href="http://www.url.com?siid=9/2-9202.jpg" class = "cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:'inside'"> <img src="http://www.url.com?siid=9&64,64,1,452849676" alt="thumb" width="64" height="64" class="thumb-picture" /></a></a></li> <li class="one_third "><a href="http://www.url.com?siid=17/2-9203.jpg" class="cloud-zoom-gallery" rel="useZoom: 'zoom1'">“<a href="http://www.url.com?siid=17/2-9203.jpg" class = "cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:'inside'"> <img src="http://www.url.com?siid=17&64,64,1,1330882420" alt="thumb" width="64" height="64" class="thumb-picture" /></a></a></li> </ul> The primary image zooms just fine. The trouble I have now caused is as follows: - On hovering the thumbnails, they automatically zoom. They shouldn't. Rather on clicking them it should change the primary image to that image. - There is a " on the page above each thumbnail which links to the thumbnail images bigger image, and on click it shows "loading" on the primary image but doesn't actually change the image. How can I fix my code to work the way the script works he http://www.professorcloud.com/mainsite/cloud-zoom-test.htm, so the thumbnail changes the primary image and the zoom doesn't occur on the thumbnail, only the primary image? Thanks! Note: Would changing the last line `'.$imgtag.'` to `'.ecarturl($img->id,'images').'/'.$img->filename.'` be the fix? Don't want to try it before I get confirmation I need to disable a query on the products page. The URL is www.myjabberbox.com If you goto the products page, you'll see when you hover over one of the three products, you can click it to take you to another page of that product. I want to disable that. I thought the code that I'd need to modify would be under the products-page.php file but I can't seem to find the code. Notice also when you hover over the products, a mouseover color of black happens around the image/text frame, I'd like to keep that, just disable the linking... Thanks I'm developing my own CMS with a few functions and wanted to know how things are looking right now because I can't find a board for strickly CODING CRITIQUE so I put it in this board. There isn't a whole lot to go through. I know there is something wrong with my issets line but other than that just a general critique of how its shaping up? manager.php <?php session_start(); require "dbconfig.php"; require "functions.php"; if ((isset($_POST['username'])) && (isset($_POST['password']))) { $username = $_POST{'username'}; $password = SHA1($_POST{'password'}); validate($username, $password); } elseif ((!(isset('username'))) && (!(isset('password')))) { require_once "login.php"; } $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM dbusers WHERE username='$username' and password='$password'"; $result = mysql_query($sql); ?> functions.php <?php // This page defines functions used by the login/logout process function validate($username, $password) { } ?> login.php <?php include_once ("globals.php"); ?> <html> <head> <title><?php echo $shortsitename; ?> EW Manager</title> <link rel="stylesheet" type="text/css" href="<?php echo "$stylesheet"; ?>" /> </head> <body> <p id="backtosite"><a href="#" title="Are you lost?">← Back to <?php echo $fedname ?></a></p> <div id="login"> <h1><?php echo $shortsitename; ?> Manager</h1> <form id="loginform" action="" method="POST"> <p><label>Username<br /><input type="text" name="username" id="user_login" class="input" size="15" /></label></p> <p><label>Password<br /><input type="password" name="password" id="user_pass" class="input" size="15" /></label></p> <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" /> Remember Me</label></p> <p class="submit"> <input type="submit" value="Login" class="button-primary" /> </p> </form> </div> </body></html> Hello! This bit of code actually does work, I just want to check that this is the best/proper/most efficiant way of doing it. Basically i'm calling a PHP function that uses the javascripts prompt function, then returning the value that the user types in back to PHP. Most probably easier to show you. Code: [Select] <?php //prompt function function prompt($prompt_msg){ echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>"); $answer = "<script type='text/javascript'> document.write(answer); </script>"; return($answer); } //program $prompt_msg = "Please type your name."; $name = prompt($prompt_msg); $output_msg = "Hello there ".$name."!"; echo($output_msg); ?> That is the entire code, I just want to know if this is the proper way to do something like this (using javascript and PHP together) thanks guys! I have a directory list using variables Folder/ and sub folders with /Folder/, what i need to do is replace the beginning slash if there is one. I'm using a recursive command and if i use substr for example: subtr("$variable", 1); it will always remove the first character. What I need is an if statement or something to check to make sure it is a slash. ok so i wan to use substr but i gives me Warning: substr() expects parameter 2 to be long, string given in C:\xampp\htdocs\ede\index.php on line 48 here the code Code: [Select] <?php include "staff/scripts/connect.php"; $query = mysql_query("SELECT * FROM headlines ORDER BY id DESC LIMIT 3"); $rows = mysql_fetch_assoc($query); $author = stripslashes($rows['author']); $date = stripslashes($rows['date']); $picture = stripslashes($rows['picture']); $headline = stripslashes($rows['headline']); mysql_close(); ?> <h2 class="boxtitle">Latest Headlines</h2> <?php do{ ?> <div id="boxhome"> <img src="staff/headlineimg/<?php echo $rows['picture']; ?>" width="100px" height="90px" class="boximg"></img> <div class="boxtitle1"> <font color="#A61E0A"><strong><?php echo $rows['title']?></strong></font><br> <?php echo substr(0,$headline,6)?> </div> </div> <?php }while($rows = mysql_fetch_assoc($query))?> </div> Is it possible to get substr to end on a word boundry instead of halfway through a word? Code: [Select] $txt = "The cat goes splat on my bumper mat"; echo substr($txt, 0, 120); //this can be around 12 chars so doesnt need to be exactly 12 chars what im trying to d is substr a table name just to get the fisrt character so i can use it as an AS...example FROM news AS n $table = "news"; $as = substr($table, 0, 1); sigular named tables are fine...but if the table is named something like this news_comments and have many underscores i want it to return nc...what is the best way to achieve this please? $num = 27; $first_digit = substr($num, 0); $last_digit = substr($num, -1); echo $first_digit; //this returns 27 echo $last_digit; //this returns 7 In the above example why is the first echo statement returning the full number whereas the second returns the last digit? (I know why the last digit is returned in the second the real question is why wouldn't the first return 2?) Edited June 23 by TechnoDiverIf I were to split this variable in half: Code: [Select] $one = none:0 Using this bit of code: function cut($string) { $string = substr($string, strrpos($string, ':')); $string = str_replace(':', '', $string); return $string; } Is it possible to get the part of the string that comes after the : in $one? EDIT: I suppose I could add another : at the end of the string and get the position of the last occurrence, but I'm curious if their is an easier method. I have front page and page for news, and i wonna to set, on front page to show news but only 100 characters, and on news page to be all text, i done that with substr($news, 0, 100); but i have proble, when i have in $news text like this: Code: [Select] Hi everyone. <b>Bold</b>now, subsrt count <b> and </b> like characters, how can i escape that <b> </b>, <u> </u> and other? Ok, I'm stumped on this one. I'm looking to strip html code from the following output: Code: [Select] <?php echo substr($f7,0,60); ?> How do I insert the strip_tags into that statement? Hello,
A not so experienced PHP-user here. For my school assignment, I have to make the following:
"Stolwijkstraat 8" has to be shortened into SW with use of SUBSTR and STRTOUPPER.
My question:
1. How can I be able to use SUBSTR and STRTOUPPER in the same line?
2. How can I be able to remove everything in the line ''Stolwijkstraat 8", on behalf of ''S'' and ''w''?
A quick response would be greatly appreciated.
Kind regards.
Hi guys, I would like to ask your help on how to trim the output (title). for example the title is "php freaks rocks" it should be "php freaks..." Thanks.. Code: [Select] <?php $Url_Path = ""; $data_dir = "" ; $images_dir =$Url_Path."/images/"; $rel_dir = ""; //Database Setting //You must change these values in order to run this script //These value are not visible in the output page source $host = ""; //Server Name $user= ""; //Username $password= ""; //Password $database=""; //Photopost database name or forum database name //Display Setting (Changes to fit your page) $q_switch = "latest"; // "random" or "most_views" or "latest" $limit = 3; //number of image to show // CSS Setting (optional) $class_photopost = ""; $class_gallery = "gallery"; // ************************************************************************* // ************************************************************************* ///////////don't edit below this line if you are too afraid to kill the code////////////// // ---------------------- THESE FUNCS FROM pp-inc ----------------- function mysql_query_eval( $query, $database ) { global $Globals; $mysql_eval_error=""; $mysql_eval_result = mysql_query($query, $database) or $mysql_eval_error = mysql_error(); if ($mysql_eval_error) { if ( $Globals{'debug'} == 1 ) { $letter = "An error was encountered during execution of the query:\n\n"; $letter .= $query."\n\n"; $letter .="The query returned with an errorcode of: \n\n$mysql_eval_error\n\n"; $letter .= "If you need assistence or feel this is a 'bug'; please report it to our "; $letter .= "support forums at: http://www.techimo.com/forum/f27/index.html\n\n"; $letter .= "To turn off these emails, set \$debug=0 in your config-inc.php file."; $email = $Globals{'adminemail'}; $email_from = "From: ".$Globals{'adminemail'}; $subject="Subject: ".$Globals{'webname'}." MySQL Error Report"; $subject=trim($subject); mail( $email, $subject, $letter, $email_from ); } elseif ( $Globals{'debug'} == 2 ) { dieWell( "MySQL error reported!<p>Query: $query<p>Result: $mysql_eval_error<p>Database handle: $database" ); exit; } return FALSE; } else { return $mysql_eval_result; } } function get_ext( $filename ) { $photolen = strlen($filename); $RetVal = substr( $filename, $photolen-3, $photolen); return $RetVal; } function get_filename($filename) { // strip off the last 4 $len = strlen( $filename )-4; $RetVal = substr( $filename, 0, $len); return $RetVal; } // ---------------------- THESE FUNCS FROM pp-inc ----------------- // Connecting, selecting database $link = mysql_connect ("$host", "$user", "$password") or die ('I cannot connect to the database.'); mysql_select_db ("$database")or die("Could not select database"); // Here is the hacked up display_gallery($q_switch) $catquery=""; if ( IsSet($cat) ) { $querya="SELECT catname FROM photopost_categories WHERE id=$cat"; $catq = mysql_query_eval($querya,$link); $catr = mysql_fetch_array($catq); $catname = $catr['catname']; mysql_free_result($catq); $queryb = "SELECT id FROM photopost_categories WHERE parent='$cat' ORDER BY catorder ASC"; $boards = mysql_query_eval($queryb,$link); $cnt=0; while ( $row = mysql_fetch_array($boards, MYSQL_ASSOC)) { $catqid = $row['id']; if ( $cnt == 0 ) { $cnt=1; $catquery .= "$catqid"; } else { $catquery .= ",$catqid"; } } mysql_free_result($boards); } // Connecting, selecting database // Selecting method and Perform SQL query switch ($q_switch) { case "most_views": if ( !IsSet($cat) ) { $group_title = "Most Popular Images - All Categories"; $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat ORDER BY views DESC LIMIT $limit"; } else { $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat AND cat in ($catquery) ORDER BY views DESC LIMIT $limit"; $group_title = "Most Popular Images - $catname"; } break; case "latest": if ( !IsSet($cat) ) { $group_title = "Most Recent Images - All Categories"; $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat ORDER BY date DESC LIMIT $limit"; break; } else { $group_title = "Most Recent Images - $catname"; $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat AND cat in ($catquery) ORDER BY date DESC LIMIT $limit"; break; } break; default: if ( !IsSet($cat) ) { $group_title = "Random Images - All Categories"; $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat ORDER BY RAND() DESC LIMIT $limit"; break; } else { $group_title = "Random Images - $catname"; $query = "SELECT id,user,userid,cat,title,bigimage,views FROM photopost_photos WHERE bigimage!='' AND approved='1' $exclude_cat AND cat in ($catquery) ORDER BY RAND() DESC LIMIT $limit"; break; } break; } $i = 1; $e = 2; $col_val = $column; $result = mysql_query_eval($query,$link) or die("Query failed"); print "<ul class=\"".$class_gallery."\"> "; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $photo_name = get_filename( $line['bigimage'] ); print "<li>"; $theext = get_ext( $line['bigimage'] ); $thecat = $line['cat']; $temp_user = ($line["userid"]); $filepath = "$data_dir"."$thecat/thumbs/$photo_name.$theext"; $image_stats = getimagesize( $filepath ); $width = $image_stats[0]; $height = $image_stats[1]; $rel_path = "$rel_dir"."$thecat/thumbs/$photo_name.$theext"; print "<a class=\"".$class_photopost."\" href=\"$Url_Path"."showphoto.php?photo=".$line['id']. "\" title=\"".$line["title"]."\">"; if ( file_exists( $rel_path ) ) print "<img src='$filepath' alt='$filepath' width='$width' height='$height' /></a>"; else print "<img src='".$images_dir."nothumb.gif' alt='$filepath' width='$width' height='$height' /></a>"; if ($q_switch == "most_views") { print "<br />".$line["title"]."<br />".$line["views"]." views"; print "</a>"; } else { print "<br /> <a class=\"".$class_photopost."\" href=\"$Url_Path"."showphoto.php?photo=".$line['id']. "\" title=\"".$line["title"]." ".$line["views"]." views\"> ".$line["title"]."<br />".$line["views"]." views"; print "</a></li>"; } } print " </ul> "; // Closing connection mysql_close($link); // mysql_close($db_link); ?> when i am cutting the character (arabic language,other international languages) with 450 in IE squrebox showing and in Firefox "?" showing. so issue is showing with other languages also . how to slove this issue.. no proplem found with iff we use wordpress.how we can remove ? thanks in advance Hello, I am trying to use the php function string substr ( string $string , int $start [, int $length ] ) to remove trailing zero's in the DB from the price displayed on the page. Currently using the code below I get this for output - $27.9500 <?php echo $row['prodprice']; ?> I would like to get this $27.95. So I tried using the string substr ( string $string , int $start [, int $length ] ) like this - <?php echo substr("$row['prodprice']",0,5); ?> but I receive t string errors and such using variations of this. Can someone please explain to me what I am doing wrong and give me some pointers on how to fix this? Thanks |