PHP - Split A String - Or Can You?
I need to split a string, but in a very unusual way.
$string1 = "HelloWorld" $string2 = "AlphaBravo" $string3 = "BreakMeUp" I need the following split at each upppercase letter for this output Hello World Alpha Bravo Break Me Up Similar Tutorialshi everyone, i have a string as this one: 45,3455,66,8900,2,49,88,8,909 I need to print it with a new line every 4 numbers, as this one: 45,3455,66,8900, 2,49,88,8, 909 How can i do this? many thanks I've been trying to figure out how to split up strings such as the following: A54a1, 23b, FX49s1, R231z, 77 I would like to split them up and add them to individual arrays that are as follows: index[0] -> alphabetical characters, if any, prior to the first number, if any index[1] -> numerical characters, as a number, up until the following alphabetical character index[2] -> alphabetical character(s), if any index[3] -> numerical characters following the second alphabetical character set, if any So, for example, the above strings would be separated like this: A54a1 == ('A', 54, 'a', 1) 23b == (, 23, 'b',,) FX49s1 == ('FX', 49, 's', 1) R231z == ('R', 231, 'z',,) 77 == (,77,,) I've looked into things like strpos(), but I can't figure how to determine whether a character is alphabetic or numeric. And yes, I am familiar with the function is_numeric(). Just don't know how to throw it all together to accomplish what I need. Hello, I have a string that contains a directory path much like: "/images/icons" and I want to take that string through a function and explode it into an array of directories that with add my directory structure array: images icons Then if I were to send the string "/data/documents" to the function it would append to the existing array: images icons data documents Here's the code that I've got thus far: <?php $global_structure = array(); generate_structure("./images/icons"); generate_structure("./data/documents"); function generate_structure($directory) { if(!is_dir($directory)) return false; $directory_structure = explode("/", $directory); // do something here to iterate over $global_structure and add new directories to equal to current directory path making the value an empty array. } ?> I have a large amount of text, (text can be different at any time), I count the number of characters in the string,and divide it by 2 so that half of the text will be in one variable, the other half in the other, however I am not sure how to get the split function, or whichever function to split it by the number of characters. example: $text = "lorem ispum dolar sit amet, consecterur adiscing elit. Donec dictum placerat sapien, in eliefend liber"; $cut = strlen($text)/2; //(here's where i cannot get it to work/do not know which function to use and how to use it) //but what I want it to do is to split it half way. We have a database that shows for example: 2500-5000 5000-10000 10000-15000 15000-20000 I need to show in a screen what people are have 3000 followers, and as such as grouped into that 2500-5000. The best way I can see how to do this, is to run through the database table for these values. Then for each value, put the first and second set of numbers into two respective variables, say $low, $high. Then find those people who are on a particular platform with followers between those two values. So how do I turn $row->followsrange (which might be for example: "2500-5000"), into:
$low = 2500 Many thanks. ps I have a feeling the hyphen might play a bit part, as it cannot be done by the amount of characters.......... My string is like this: line 1 line 2 .... line 3453 line 3454 etc... I want to split the string into chunks of 500 lines, do something with those chunks and then reassamble the main $string again. The last chunk doesn't need to be 500 lines it can be less. How can I do it? Hi! So what I'm trying to do is split a multi dimensional array of strings ( each containing 3 strings inside of 1 array ) so I can write the results to a file. So say I had a bunch of strings inside 1 array : class File { function WriteFile ( $filename, $content ) { $list = [ $content ]; $delimiters = File :: checkDelimiter ( $content, true, false ); $fp = fopen ( $filename, 'w' ); foreach ( $list as $fields ) { $fields = File :: SplitFileByDelimiter ( $fields, ",", 3 ); file_put_contents ( $filename, $fields ); } fclose ( $fp ); } } $file-> File :: WriteFile ( $filepath . $filename, "TEST!, TEST!, TEST!, " . "TEST!, TEST!, TEST!, " . "TEST!, TEST!, TEST!" ); Instead of writing : TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST! ,TEST!, TEST!, TEST! to the file in a straight line, it should write it like this : TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST! Any help is ABSOLUTELY appreciated! Edited May 22 by AquariaXI How could I split a string in half but not in the middle of a word? $information = "This is the string of text, however at some point in the sentence a word may get split in half."; $cut = round(strlen($information)/2); ///where to cut (50%) $split1 = substr($information, 0, $cut); //first half $split2 = substr($information, $cut); // second half Hi, 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 What's the best string function to use if i want to split a string up affter a specific character? In this case i have a var with "uploads/thisImage.jpg" i want to split this so i can create a new var value of "thisImage.jpg" How can I split this data and then remove it? I need to split data by ; then split each one of those. $data = "page=1&data=1:21;2:34;5:57&a=yes"; So I will get: $category[0] = 1; $sub_category[0] = 21; $category[1] = 2; $sub_category[1] = 34; $category[2] = 5; $sub_category[2] = 57; i have same problem like you, if i open a small file(3 to 5mb), open normal. But, when i try open a dbf file 13mb or more, cause php.exe error; i set Mem in php.ini to 256mb(before 8mb), but doens't work. Someone have some solution, because i try find some way to clipper program input data on MySQL and dont have sucess too... Hi all, hopefully just a quickie. split is deprecated in 5.3, but i have the following to get working.. Code: [Select] $dest = split(self::__MAIL_DELIMITOR__, $this->_mails); delimitor is as follows: Code: [Select] const __MAIL_DELIMITOR__ = ',';and _mails is just a list of email addresses. Can anyone suggest a workaround? Thanks i have a set of array's with a similer layout as t127201103111200 what i need to do is split it like this t:1:27:2011:03:11:1200 (where the : is where i want the split but not add the : ). so i end up with this. $a = t $b = 1 $c = 27 $d = 2011 $e = 03 $f = 11 $g = 1200 what i think i need to do is Code: [Select] split(char1($a), char2($b), char3,4($c)...........................) but have no idea where to start. Thanks for any help I'm pulling 10 records here. How do I split the results in to several echos? $query = "SELECT statez, COUNT(statez)FROM mylist GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> I need the code to look like this by showing the (COUNT) number for each state. $results = mysql_query($query); while($line = mysql_fetch_array($results)) { echo $line["number_in_state1"].",,"; echo $line["number_in_state2"].",,"; echo $line["number_in_statee3"].",,"; echo $line["number_in_state4"].",,"; echo $line["number_in_state5"].",,"; echo $line["number_in_state6"].",,"; //etc.... } How do i specify that i want the fgetcsv() to use a ; to separate instead of a , p.s.(i have no control over the .csv file so i cant change it from ; to ,) 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 } } } } 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! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 |