PHP language arrays and text [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a text box and I wrote some text in it.
the question is, how to put the written text inside an array, and then use the explode function to separate each word ?

first get the value like this (I assume that you have a form and you send it by POST):
$name_of_array = $_POST['name_of_your_form_field'];
$separeted_vars = explode(' ', $name_of_array);
I hope this help you!
p.d: the $name_of_array isn't necessary that be array...

Something like this:
<?php
$words = explode(' ', $_POST['textbox_contents']);
?>

"this is some text to be separated" // this is written in a text box with a button called separate
the array is gonna be used in the explode function
the expected result is
this
is
some
text
to
be
separated

Related

How i can earn variable from string in PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a $string = "domain.com/path?query=test";
I need to get of it 2 variables: "domain.com" and "path?query=test"
And then i need transform this variables to looks like this "domain.com/api/path-2?query=test-2"
How must this code looks likes? And it means i need to use function?
Thanks you!
This should work for what you are trying to achieve
$string = "domain.ou/path?query=test";
$str_arr_domain = explode ("/", $string);
$str_arr_params = explode ("?", $string);
$newpath = "/api/path2/";
$final_url = $str_arr_domain[0].$newpath.$str_arr_params[1];
print_r($final_url);

Get only all the visible text from a url [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to get all the visible text from a url. I need to clear all html code and get plain text.
The process does not have to be perfect, but I would like the text to be as clean as possible.
Do you know any way to make it relatively simple?
Thanks!
Javi.
Have a look at strip_tags function.
strip_tags — Strip HTML and PHP tags from a string
It may do the job.
You can get url the value of the query string using $_GET['the names in there']. and use strip_tags to get only the text.
function get_url(){ return $_GET['name userd'];}
and use something like this

How to detect a newline with space [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
my string is "mom dad" (also saves the same attribute in table db).
After I query and print to the table, I want to separate a newline with a space. The output should be mom+newline+dad, but it prints "mom dad" without a new line.
Use PHP explode() function like this :
<?php
$input = "mom dad";
$inputArray = explode(" ", $input);
//now inputArray is like this ["mom", "dad", ...]
echo $inputArray[0]."<br>".$inputArray[1];
?>
Hope it helps
Thanks

Prepend and append to each variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
First question here!
I have some PHP variables all in the form of the below, in around 7/8 different files.
$this->do['string']
I wish to make them all into the following:
myfunction($this->do['string'])
I understand I have to use regex and the get file contents function, but I'm unsure where to go from here! Would be very grateful if someone can assist!
Thanks in advance
How about:
$result = preg_replace("/(\$this->do\['[^']+'\])/", "myfunction($1)", $inputstring);
Edit according to comment:
In the comment you said that your input string is: $inputstring = "\$this->do['fsdfs']"; (with a backslash before $this). You have then to add the backslash in the regex and also escape it, so the whole instruction becomes:
$result = preg_replace("/(\\\$this->do\['[^']+'\])/", "myfunction($1)", $inputstring);
// ^^^

Finding the right line and get data out of it [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a file that contains lines that look like this:
{"name":"RandomName1","level":20,"class":"something","experience":2688746894},"account":{"name":"RandomAcc1","challenges":{"total":0}}},{"online":false,"rank":172,"dead":false,"character":
{"name":"RandomName2","level":21,"class":"something","experience":2687863942},"account":{"name":"RandomAcc2","challenges":{"total":0}}},{"online":false,"rank":173,"dead":false,"character":
{"name":"RandomAcc3","level":22,"class":"something","experience":2687280914},"account":{"name":"RandomAcc3","challenges":{"total":0}}},{"online":false,"rank":174,"dead":false,"character":
I want to search for a name, for example "RandomAcc3", if the name is found, check the "online" status in that line and extract that into a boolean. Any help is much appreciated!
read the file, json_decode into an array, fetch the array (foreach) and check if the current subelement contains the string (substr/preg_match). if so, you'll consider/return the "online" element. hope you have a bit of coding skills to write it yourself, otherwise use codeacademy, not stackoverflow
$fileContent = file_get_contents($filepath);
preg_match('/"name":"RandomAcc3"(.*)"online":([a-z]+)/i', $fileContent, $matches);
$onlineStatus = ($matches[2] == 'true');

Categories