PHP - Inject String At A Certain Position
Hey all, If I have a number like this: 1245 then I want a '.' inserted at position -2: 12.45 how do I do that in the most simple and elegant way?
74342 -> 743.42 Similar TutorialsHi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this!
In PHP Version 8.0 shows error as : In previous versions of PHP it does not show any error. Please resolve the issue. Hello guys i am trying to figure out how to fwrite a string for example "Recommended Settings for Service Pack" under "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600". I figure i cant use line number as an argument because the file report may be dynamic so i will need to use Current Settings as an argument. Please guide me if you have any ideas..thanks:) ! auditreport table ServicePackSetting Service Pack Requirement: Fail Current Settings for Service Pack: 5.1.2600ServicePack3Build2600 MajorAuditandAccountPolicies Maximum Password Age Requirement: Fail Current Settings for Maximum Password Age Requirement: 42 Minimum Password Length: Fail Current Settings for Minimum Password Length Requirement: 0 I need to know if a string exists within a string. I've tried using STRIPOS() but it returns zero or false if what I'm looking for is the first part of the string. I don't care what function I use, but I need to get a "true" when the needle string is present anywhere in the haystack string, even at location zero. Is there some way to set up the STRIPOS() statement? I've tried: if ((stripos($title, 'needle') > 0 ) if ((stripos($title, 'needle') = true ) and even if ((stripos($title, 'needle') >= 0 ) which returns true for everything, even when the needle string is NOT present. Any help appreciated. thanks, Tom Ok... I had typed this post out ONCE already and when I clicked REFRESH IMAGE to get a diff captcha it ERASED MY POST LMAO this is not my night.... What I need help with is probably more simple then I can even think right now - ive been digging at this for 3 hrs now and im out of time for the night I have a DB Record storing ID's between PIPES | when the initial entry is made in DB it stores it like so |47| NOTE: the number could be different these are ID's number doesnt matter its just between Pipes When the second entry is added its added like so |47||67| say we have a total of 5 Entries |47||67||82||55||69| I need to find ID 82 in that string and it has to be between Pipes Find 82 in data between | and return that ID 82 I am putting between pipes because the ID's can be duplicate digits in different lengths so say I have 8 as my ID and down the string i have another id as 88 -- I cant possibly find the correct ID without some sort of seperation character so i used Pipes soo my end goal is the ability to search and if true or false do action if ($result == $find_id){ echo "ID is there"; }else{ echo "NOT THERE -- Adding it"; } Any help is appreciated guys Thanks SangrelX I am looking for a date within larger string, lets say the date is December 4, 2010. To find it I use pattern and function below: $Pattern='/[(January|February|March|April|May|June|July|August|September|October|November|December)] \d, \d\d\d\d/i'; preg_match_all($Pattern, $String, $Matches, PREG_OFFSET_CAPTURE, $NumberPosition); The function finds the dates within the string but to my supprise the result I get in $Matches is: r 4, 2010 What I would like to get is: December 4, 2010 but don't know how it should be fixed. I thought that with the pattern I am using but obviously that is not the case. I'm trying to do some regex, but I'm having trouble with my input string for the regex. I'm querying a server and getting results from that via socket and trying to regex the results and extract content. I've got the regex working (thanks to mjdamato ), but it only works when I have the regex string like this: $input = "hostname: Hooter's GG 5.1 Elimination HLstatsX:CE version : 1.0.0.58/15 4426 secure udp/ip : 25.2.132.39:27015 map : fy_dustdm at: 0 x, 0 y, 0 z players : 0 (20 max) # userid name uniqueid connected ping loss state adr "; When I get the results from my socket it's stored in a variable and it doesn't work when it's exactly the same. I did var_dump on the results from the socket and this is what it outputs: string(229) "hostname: Hooter's GG 5.1 Elimination HLstatsX:CE version : 1.0.0.58/15 4426 secure udp/ip : 25.2.132.39:27015 map : fy_dustdm at: 0 x, 0 y, 0 z players : 0 (20 max) # userid name uniqueid connected ping loss state adr " Since it's exactly the same why doesn't the second way work? Let me know if this is too confusing.. hey guys just a simple one...im trying to replace {$name} but i dont think ive got the right prefix in the str_replace function...if anyone could tell me where i am going wrong please $content = str_replace("{/$".$variable."}", $value, $content); {$name} Given a text value $path, I want to return the actual path. One option is a switch statement as shown below. Another option is put them in an associated array (or maybe a static array?) and check if the element is set and if not throw an deception. Or maybe a totally different solution. Is one solution better (i.e. more efficient) than another? I will probably be retrieving a path around 5 times for every server hit. Thanks
function getPath($path) { switch($path){ case 'classes': $path=__DIR__;break; case 'application': $path=dirname(__DIR__);break; case 'root': $path=dirname(dirname(__DIR__));break; case 'twig': $path=dirname(dirname(__DIR__)).'/vendor/autoload.php';break; case 'lib': $path=dirname(__DIR__).'/lib';break; case 'help': $path=dirname(__DIR__).'/lib/help'; case 'templates': $path=dirname(__DIR__).'/lib/templates'; case 'htdocs_base': $path=dirname(dirname(__DIR__)).'/html'; case 'resources_base': $path=dirname(dirname(__DIR__)).'/user_resources'; // About 10 more default: throw new Exception("Path {$path} not valid."); } return $path; } Hi, I have 2 pages, config.php and category.php config.php is Code: [Select] class CategoryWork { public $form = ""; public $error = ""; public $add_form = "<br /><p><strong>Add New Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=add\"> <table width=\"550\" height=\"170\" border=\"0\"> <tr> <td width=\"153\">Name :</td> <td colspan=\"2\"><label for=\"cat_name\"></label> <input name=\"cat_name\" type=\"text\" id=\"cat_name\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Slug :</td> <td colspan=\"2\"><label for=\"cat_slug\"></label> <input name=\"cat_slug\" type=\"text\" id=\"cat_slug\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Description</td> <td colspan=\"2\"><label for=\"cat_desc\"></label> <textarea name=\"cat_desc\" id=\"cat_desc\" cols=\"48\" rows=\"10\"></textarea></td> </tr> <tr> <td> </td> <td width=\"97\"><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> <td width=\"286\"><input type=\"reset\" name=\"button2\" id=\"button2\" value=\"Reset\" /></td> </tr> <tr> <td> </td> <td colspan=\"2\"></td> </tr> </table> </form>"; public $edit_form1_first = "<br /><p><strong>Edit Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=edit\"> <table width=\"454\" height=\"79\" border=\"0\"> <tr> <td width=\"110\">Category :</td> <td width=\"334\"><label for=\"select\"></label> <select name=\"select_cat\" id=\"select\">"; public $edit_form1_last = "</select> </td> </tr> <tr> <td> </td> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> </tr> </table> </form>"; public $invalid_get_error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Invalid Option.</em></strong></font></p>"; public function CheckAction($action){ if(!isset($action)) { header("Location:dashboard.php"); } else { $action = $action; if($action == "add") { $this->form = NULL; $this->form = $this->add_form; } else if ($action == "edit") { $this->form = NULL; $this->form = $this->GenerateDropDown(); } else if ($action == "del") { $this->form = "del"; } else { $this->form = $this->invalid_get_error; } // if else .. else if ends here }// if else ends here } // Function CheckAction ends public function ValidateAddForm($name, $slug, $desc){ if(isset($name) || isset($slug) || isset($desc)) { if($name == NULL || $slug == NULL || $desc == NULL) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : All 3 fields are required.</em></strong></font></p>"; } else { // Data Insert in database $name = $name; $slug = $slug; $desc = $desc; $check_category_query = "SELECT * FROM category where slug = '$slug'"; $check_category_result = mysql_query($check_category_query); $check_category_count = mysql_num_rows($check_category_result); if($check_category_count == 1) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Slug Already exists.</em></strong></font></p>"; } else if ($check_category_count == 0) { // Do insertion in database $categoryinsert_query = "INSERT INTO category (name, slug, description) VALUES ('$name', '$slug', '$desc')"; $categoryinsert_result = mysql_query($categoryinsert_query); $this->error = "<br /><br /><font color=\"#009900\"><p><em><strong>Success, Category added.</strong></em></p></font>"; } } } } // function ends here public function GenerateDropDown(){ $dropdown_query = "SELECT * FROM category ORDER BY name"; $dropdown_result = mysql_query($dropdown_query); echo $this->edit_form1_first; while($row = mysql_fetch_array($dropdown_result)) { echo "<option value=".$row['id'].">".$row['name']."</option>"; } echo $this->edit_form1_last; } // end of GenerateDropDown function } Here is the code of category.php page Code: [Select] <?php include('config.php'); $system = new SystemAdmin; $categorywork = new CategoryWork; $system->ValidateToken($_COOKIE['token']); $categorywork->CheckAction($_GET['action']); $categorywork->ValidateAddForm($_POST['cat_name'], $_POST['cat_slug'], $_POST['cat_desc']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome <?php echo $system->username; ?></title> <?php echo $system->metalines; ?> <?php echo $system->slug_javascript; ?> </head> <body> <h1>Welcome <?php echo $system->username; ?>,</h1> <?php echo $system->mainmenu; ?> <?php echo $system->spryfunctions; ?> <?php echo $categorywork->error; ?> <?php echo $categorywork->form; ?> </body> </html> Problem is that when I go to /category.php?action=edit, it shows dropdown at the top of page and not at the position of <?php echo $categorywork->form; ?> I have attached a screenshot, please go through it. How can I solve this ? Second problem is how can I hide undefined index notice ? I'm looking for one or two talented Laravel guys in the Dallas area who write clean code, document well, and love pushing the limits of their own abilities. It is important that the developers we hire are local. Please do not respond if you do not live in the Dallas area.
Preferred knowledge
- Laravel
- AngularJS
- NodeJS
- jQuery
- MySQL
- HTML/CSS
- e-Commerce
- Paranoid about security
- Performance minded
We are developing applications that will process millions of dollars in transactions every month. Performance, security, and the ability to scale is paramount.
Thank you
I have a query at the moment that gives a name, number of rides and number of points
SELECT COUNT( `points` ) AS 'rides', SUM( `points` ) AS 'pts', rider_name FROM tbl_heat WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESCwhat I want to do now is add the position in a league table, I have tried amending the query and have the following SELECT @serial := @serial +1 AS pos, rider_name FROM( SELECT COUNT( `points` ) AS 'rides', SUM( `points` ) AS 'pts', rider_name FROM tbl_heat JOIN ( SELECT @serial :=0 ) AS init WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESC ) as sortedhowever this query doesn't give what I am after, not sure how far off getting it right, any help would be great Hello. i have created a template in dreamweaver, however when i added php code to a page the position of my bottom div got messed up... it works 100% with just text. I have a container div with other divs in it. inside the container div i have a div named content, and this div is the only div which is editable. in the bottom (outside of the container div) i have a bottom div which is centered with margin:0 auto; this divs position gets totally messed up once i add php code in the content div. http://elevweb.skit.no/0111nema/action_adventure.php here is the link to the page with php with it, as u can see the div with facebook etc in it got a messed up position. Hi all, Not sure if this is a browser feature kind of thing, or if it can be done with a script. I'm looking at my page: www.mysite.com/index.php?start=0 I scroll to the bottom of the page with the vertical scroll bar, and then click the pagation link to start on page 2, record #50: www.mysite.com/index.php?start=50 Of course, the vertical scroll bar jumps back to the it jumps to the top of my page. Is there a way to make it remember that the scroll bar was at the bottom (or in the middle)? Thanks. |