Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Finding A Space In A String


I am trying to find a space in a string. If I have a sentence like:

This is a sentence.

I would like to be able to find the second space form the endand then return that part of the sentence, so if I ran it on that sentnece above it would return "a sentence.", but I won't know what the sentence is.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Finding Local Disk Space
how to find the local disk space in php? I tried the command df -h, it gives me the details of the space for local drives as well as for all the mapped drives. All I want is to get the disk space of local drives. df -l, doesnot work. I can get the space details if I hardcode the drive letter. Need to find the local disk space without hardcoding the drive letters.

Checking String For Max Length Without Space
I have a form where people enter their username. I have a limit of 50 characters for their name (that's easy enough to police) but much trickier is this. They can't have more than 15 consecutive letters without a space. If they do, it throws out the formatting of my HTML tables. Is there a way in PHP to check that there is never a sequence of 15 or more letters without a space in a string?

Removing Space Characters From A String
How do I remove space characters from a string using PHP?

For example, the following string...

' hi there, my name is burnsy '

....has spaces, at the edges and inbetween the other characters. I know
I can use trim() to remove the outside ones but how do i remove the
inbetween ones so it will read:

'hithere,mynameisburnsy'

Add An Extra Space After Period In A String
I want to be able to add an extra space in each instance
after a period in a string. I am already stripping out extra
whitespace throughout, so to start I have a nice flat string to work
with. I am struggling getting the syntax right and keep getting funny
results. What is the simplest way to accomplish this?

Netscape Truncating String At Space
While using the following commands with Netscape the "string" gets truncated to the first occurence of a space. Code:

Detect Upper Case Characters In A String And Separate Them With A Space
I want to detect uppercase characters in a string and separate the two
words in it by a space. I know I can use preg_replace for it, but I am
not very good at regular expressions. Can someone help?

One example of such a string follows. Please note that there are a lot
of strings like these and I want a generic method to do it, which is
why I think preg_replace would be the perfect solution.

Example:

$string = "UserLocation";

I want the string to be $string = "User Location";

Finding @ In String
What's an easy way to tell if a string contains the @ char?

Finding A Value Within A String
Say I have a string, for example: "Name: bob, Age: 22".

I know that there is a name stored in there and that it is in that format. How can I trim that string down until it's left with just the name?

Finding @ In A String, And Other Items
Ok - I want to check a string for @ in it (Im checking to see if a string
that should contain an email holds a @ )

How would I go about this? preg_match? ereg? strstr? Examples?

Also - how would I find any non alpha numeric characters in a string so I
can give the user an error message. I dont want any characters besides
alpha-numeric in the strings.

Finding And Extracting From A String
Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn it
into array so that I can later operate on these strings.

And second, variation of it:
To get whole lines that contain some characters like 3 digits from a number
second b) :)
to extract only nmbers with some digits not whole lines.

Finding Spaces In A String
I am now looking for a way to go through a string variable, find any space that is present and replace it with _.

How would I go about?

The reason is I get input from a user.. lets say he/she loads a variable $Hockey = "Edmonton Oilers";

this variable is used to create a new webpage but of course, the web does not like spaces.. hence I would need this variable to be $Hockey = "Edmonton_Oilers";

Finding Number In A String Of Numbers
I have a string of numbers separated by comma ',', eg
$str = "1, 3, 56, 8, 9, "; (there's a comma at the end, because it was easier for me to do so)

I need to compare a number ($id) if it's in the string. At first I thought, that strpos() will do the trick, but then it struck me, that 6 will be found (because of 56, ).

Finding Fourth Instance Of A String? (4th, 5th, Whatever)
strstr() will find the first instance of a string.

But how would you find, say, the 4th instance of a string?

Problem Finding Occurances Of One String Within Another
Can anybody see what is wrong with this code? apparently i have an 'empty
delimiter' on the line that sets $pos - can anybody see what is wrong with
it?

$search_for = $_GET['for'];
$the_items_description = $row ["description"];
$pos = stristr($the_items_description, $search_for);

if ($search_for == "") {
$does_contain_text = true;
} elseif ($pos === false) {
$does_contain_text = false;
} else {
$does_contain_text = true;
}

// end text search
if ($does_contain_text == true) { // rest of page works fine

Finding The Longest Word In A String
Is there a php function to find the longest word in a word list or sentence?

I've got a massive list so if there isn't a function how would be the most efficient way of doing it? I've looked at playing with arrays but can't seem to find a quick and easy way...

StrPos - Finding Substring Within A String
I just wanted to know how to find every occurrence of a sub-string in a string?

I would like to find the positions of every occurrence of a word within a sentence.

CodingForums is a web code and development forum

In the above sentence, I would like to have an array with the positions of all occurences of the letters "or" (2 occurrences in this case). I'm sure strpos can do this, can any one provide a function or the code necessary to do this?

Finding First And Last Char Positions In An Alphanumeric String
How do I find the first and last non-numeric char positions (using
regexp) in an alphanumeric string?

For example,
99ABC1A => should return 2, 6
DE8A1 => should return 0, 3

Remote Server Disk Space & Free Space
how can i get the remote server disk space & free space by using php script?

Form Validation - Finding Duplicates: Regular Expressions Or String Functions?
I'm trying to figure out the most efficient method for taking the
first character in a string (which will be a number), and use
it as a variable to check to see if the other numbers in the string
match that first number. I'm using this code for form validation of a
telephone number.

Previous records from the past few months show that when someone is
just messing around on one of our forms (to waste our time), they type
in a phone number like "555-555-5555" or "111-222-3333". Our Web forms
have three text boxes for each telephone number:

homephone1 = area code (3 digits)
homephone2 = prefix (3 digits)
homephone3 = suffix (4 digits)

businessphone1 = area code (3 digits)
businessphone2 = prefix (3 digits)
businessphone3 = suffix (4 digits)

My plan is to check for this pattern, then if I find it, just redirect
the user to the thank you page so they'll think the form was
processed, when it actually wasn't.

As we find additional patterns that people use for malicious data,
I'll enter those as well (e.g., 123-123-1234)

Also, if you see any tutorials, or articles that talk about "real
world" form validation please point me to them. I've been looking for
references for form-based validation logic that takes real world dummy
data into account, but haven't found much.

Regular Expression Space And 2 Byte Space
When receiving a particular string and if the string has a space/ 2 byte
space with some trailing string.
I want to remove the trailing string.

$somestring = "some string";
$match_pattern = "/(.*)s.*/iu";

preg_match_all($match_pattern, $somestring, $match );
echo $match[1][0]

Looks like this only works for single byte space.

How can I define the regular expressoin so that it finds the 2 bytes space.

Space To +
How can I take all spaces from a variable and turn them into a + char.

Variables W/ Space Gets Cut Off On GET
I'm not sure why my text spaces aren't getting changed to %20. When I click a link w/ variables in it, the next page only gets the first word contained in the variable.

Any idea why this is happening? I don't remember having to do anything when passing multiple worded values across pages.

Space Replacement
I want to replace the space between the word into hyphen (-)

like word is

SITE OPTIMISATION TECHNIQUE , i want to replace it to
SITE-OPTIMISATION-TECHNIQUE

actually i am using this system to rewrite URL to convert it to search engine
friend url i.e. mod_rewrite ...

Php Value Disappear After The First Space ?
why is the value of a php variable disappear after the first space ? i was coding :-

echo "<a href=javascript:goto('$a[0]',$a[1]')>$a[1]</a>

but if the value of $a[0] is 'T h i s' then when my mouse is over the anchor,the value is :- javascript:goto('T this is a syntax error !

Adding Space To URL
My script displays URLs of other sites, and I'm seeing that very long URLs don't wrap within the table, therefore pushing out the borders and spoiling the format.

Can anybody give me a piece of code that will take an URL variable (e.g. $url) and parse it to place a space after the 1st forward slash
(e.g. http://www.example.com/very/long/url/ would be replaced by http://www.example.com/ very/long/url/)

Alternatively, the space could be placed after the second slash, so that not so many URLs are changed this way.
(e.g. http://www.example.com/very/long/url/ would be replaced by http://www.example.com/very/ long/url/)

Getting Rid Of White Space
Anyone have a quick simple way of getting rid of white space in the middle of a string? I've tried str_replace("  ", " ", $string) but doesn't seem to do it, I guess it doesn't work with spaces?

Replacing A Space With -
If I have $town='Town Name' and it displays "Town Name" how can I get it to display "Town-Name" instead.

How Do You Get Php To Output More Than One Space?
I can write a string to the screen, but if i want to put tabs between them, php will print ONLY ONE space instead of the tab. if i replace the ' ' with 50 spaces, the screen will only output one. im trying to create a tree like structure like the following


element one
*<tab>* response to element one
element two
*<tab>* response to element two

each of the tabs is reduced to one character.

Replacing A Space With %20
I have a script that shows a list of uploaded files, with a button saying Delete.

<?PHP 

$folder = "../files/upload/"; 
$handle = opendir($folder); 

# Making an array containing the files in the current directory: 
while (false !== ($file = readdir($handle)))
{
    if ($file != '.' && $file != '..')
       $files[] = $file; 

closedir($handle); 

#echo the files 
foreach ($files as $file) { 
    echo "-<a href=$folder$file><label title=file>$file</label></a>";
echo "    [<a href=filedelete.php?file=$file>Delete</a>]<br />";

?>

Now something is very weird, because if you attempt to delete a file that has a space in it, it appears as eg:

filename: de_dust A.jpg
file comes out as: de_dust

I need some way to replace the space with that %20 thing that normally shows up in links if there is a space in it.

How Much Space A Folder Is Taken Up
How is everyone? Well I was just wondering if somebody got teach me how to make a PHP Script which tells you how much space a folder is taken up? Example: I have a folder called ./files, I want a script which will tell me howmuch space its taken up .

Regex - Just A Space
includes various characters apart from just a single " ". Is there any way to limit it just to a space and omit vf etc?

Removing A Space After Submitting
I am working on a script that creates options with a number to be inserted into an array PHP Code:

Help Removing A Simple Space
I need to check for sentences that have a space before the period and
remove the space. I've tried:

$sentence = str_replace(" .", ".", $sentence);

but it does not work. I've tried other ways with no success.

Why doesn't this work and how do I do this?

Linking To Files Which Contain A Space
I'm getting errors when I try to view a file located on the server which has a space in it's name. For example "test file.txt" gets a link of "http://www.domain.com/directory/test ". Files with no spaces such as "test_file.txt" are fine. PHP Code:

Trim After Last White Space
I have the following code which returns the first 100 characters. Now I would like to trim everything after the last white space. PHP Code:

Fwrite When Out Of Storage Space
I have a problem that has long plagued me:

What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace,

$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Do I need to write to a test file and check it's filesize first??
There's gotta be a better way.

This is a server where the log files get out of control and that's out
of my jurisdiction.

Calculating Free Space Available
Is there a way to tell how much space is remaining available for files? I'm working on a script that takes uploaded images and adds them to a database, but I'd like to check and make sure there's room for it first.

I think there's probably going to be some type of issue with quotas, because that's how I found the problem. A user had uploaded a test version and got an error that a folder could not be created because of insufficient space remaining.

And I know I could probably exec() out to df or something similar, but I would like it to work on Windows servers as well, so I'd prefer to keep it all in PHP code if possible.

Hard Disk Space
i would like to know how to find a file in the entire system, i want to create a search so that the user enters the file name and the the script searches the entire system for the file,and later on displays the result of the search.

PHP Form Space Issue
I have some code that displays 2 select boxes one on top of the other. I am trying to display them without any space between them. It doesn't seem to be possible. PHP Code:

Passing DB Values With A Space In The URL
I have written a web app that takes results from an Informix DB. this DB is part of a legacy system and as such, I cant change the data in it. i am only writing something that outputs the data.

One of the DB fields holds placenems and these in some cases are two words ie: San Diego. Now, there is a second page which produces further results depending on the placename. I pass the placename value to the next page in the URL but, and here's the problem: Normally, I pass the value like so: link.php?name=$placename If the placename is Dublin then the link would be PHP Code:

Seperating Vars From Db With Space.
What the script is going to be used for is: People can registrate a username and password. I have to check my database if anyone else have this username... Therefore I grab every username from the database, and then I make an if/else statement.
how can I seperate the results? Because if I try to "echo" $user, the results appear in one word, and not one word for each result. Code:

Remote Disk Space ...
can't manage to do it ..... was so easy under solaris ....
anybody knows how to get free disk space on remote disks ???

(with both local and remote *$#@%§&* machines running *$#@%§&* W$2000)

White Space Position
how do i find if there is white space in a string eg. "hello how are you?" also how do i return the position of that white space?

Replace Underscore _ With Space - How?
I'm developing an application for a client, and the current setup is that the entries in the database have underscores in instead of spaces, i'm persuming the previous developer did this for query reasons...

basically its town names which have a space ie 'Colwyn_Bay'how do I substitute the _ with a space in the php echo code to display this as 'Colwyn Bay' and not Colwyn_Bay?
I'm using <?php echo $searchquery_town; ?>

Space In The Download Filename
I have made a small page where users can upload files and then download them from another, however if there is a space in the filename the download will not work properly. I was just wondering if thats how things are or if there is a way round this?

Form Pass A Space?
I have a database and i create a record with $login = "carter n"

when i go to edit, it sets $login = "carter" and drops the "n"..

how can i stop this happening, while allowing the use of the space?

any thoughts?

Append Two Textfields Into A Third One With A Space
i dont know if its a stupid question but im so new to php you can forgive  me
well the thing is i have 3 text fields

textfield1
textfield2
textfield3

I want to add textfield 1 with textfield 2 and display it in a hidden textfield3 with a space between the text.

Textfield1(Sam) + Textfield2(Yam) = Textfield3 (Sam Yam)

White Space Manipulation
got a string i.e. "Hello World 2007".

aim is to remove only one white space when prompted ie. remove the first and end up with "HelloWorld 2007" or the 2nd and achieve "Hello World2007". Could be a string with more white space.

Any functions that single out a specified character? but only 1 such as take the 2nd white space but leave the first?

Database Or PHP Adding A Space
I recently had to change all my embed code to get Quicktime Player to work in Windows. Unfortunately, now my php scripts are not working properly because a white space is getting added to the end of a field in the database (even though it doesn't appear to be this way in the database). So I am looking to use regex or something to take the database field and stop when the space begins; but I'm so far from understanding regex.. Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved