I am facing an issue with my site on cars - Now the problem i am facing with CodeIgniter is that on "new car" section if I select make, the URL is like below.
http://carandme.com/new-cars/ashok-leyland-cars-in-india?car_type=new&car_type_id=1&maker_id=106&maker_identifier=ashok_leyland&model_id=&model_identifier=
but I want a URL like this.
http://carandme.com/new-cars/ashok-leyland-cars-in-india
Similarly I am also facing issue in refine search on same page i.e if I select two car, the URL doesn't changes but the parameters do. Is there any way for this to be without parameter.
$input1 = $this->input->post('user_search1');
$input2 = $this->input->post('user_search2');
$user_input = array($input1, $input2); //making array of user search Inputs
$search_field_name = array("search_col_name1", "search_col_name2"); //original column name of table fro searching
//combining to send it as uri latter
$searchparams_uri = array_combine($search_field_name, $user_input);
//removing the keys and values from the array if Values is null or not set
$searchparams_uri = array_filter($searchparams_uri);
// Convert to associative array $this->terms_uri to segments to append to base_url
$keys = $this->uri->assoc_to_uri($this->terms);
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/controller/method_name/'.'/'.$keys.'/';
You will get URL like this:
index.php/controller/method_name/search_col_name1/input1/search_col_name1/input1
Break and Make according to your need. Question are welcome.
Related
I'm doing a custom page for my WP website and for this I'm getting the content of an existing WP page. Getting the content is not a problem but I'm getting it like this :
https://youtu.be/abcdefghijkhttps://youtu.be/kjihgfedcbahttps://youtu.be/abcdefghijk
I'd like to transform it like this :
https://youtu.be/abcdefghijk
https://youtu.be/kjihgfedcba
https://youtu.be/abcdefghijk
I tried explode('/', $content) but it's not working as I want.
I don't know if I can use substr() in this case.
How can I do to separate each url properly or atleast separate each video's id ?
You can get all video id(s) as an array like this:
$str = "https://youtu.be/abcdefghijkhttps://youtu.be/kjihgfedcbahttps://youtu.be/abcdefghijk";
$videos = explode("https://youtu.be/",$str);
If you print_r($videos); you will see all the id in an array.
If you want these array values as full URLs, then do like this:
$videos = array_map(function($value) { return ' '.$value; }, $videos);
I'm currently working on a project where my current goal is to print information about the specific user on the final checkout form inputs.
First off I gather the information of the specific user through a public function:
public function getUserAddress($dbh)
{
$sql = "SELECT street, zip, city FROM address WHERE user_id=:user";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':user', $this->uid);
$stmt->execute();
$userAddress = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->userAddress = $userAddress;
return $this->userAddress;
}
Then I store the information in a variable I call $userAddress
$userAddress = $user->getUserAddress($dbh);
Since the user has two addresses, both with a "Street", "City" & "Zip" I'm storing both arrays in $templateData. This way I can specify what index should be printed out in which input tag instead of having to create a new function for each slot.
$templateData['user']['address'] = $userAdress['street']." ".$userAddress['city']." ".$userAddress['zip'];
However, printing these out seems near impossible. When I var_dump
$templateData['user']['address']
I only seem to be getting 2 empty strings and nothing else.
This is just code from my Checkout.controller but somehow the information doesn't seem to be found in my template page. All routes and includes are correct so dw about that.
I'm quite new to all this so I'd appreciate any help I can get!
Image of how the information should be presented https://gyazo.com/40fa06832207bd785ee038af4962bb1e
So in this case: "Postort" = "City" & "Gatuadress" = "Street"
PDO::fetchAll(PDO::FETCH_ASSOC) will return an array of associative arrays; so to access the individual elements you need something like:
$userAdress[0]['street']." ".$userAddress[0]['city']." ".$userAddress[0]['zip']
I could alaways define every single one of them specifically although it seems far fetched. Something like this:
$templateData['user']['address'][0]['street'] = $userAddress[0]['street'];
$templateData['user']['address'][0]['city'] = $userAddress[0]['city'];
$templateData['user']['address'][0]['zip'] = $userAddress[0]['zip'];
$templateData['user']['address'][1]['street'] = $userAddress[1]['street'];
$templateData['user']['address'][1]['city'] = $userAddress[1]['city'];
$templateData['user']['address'][1]['zip'] = $userAddress[1]['zip'];
I'm basically looking for another solution which doesn't require so much repetition.
I am making a price crawler for a project but am running into a bit of an issue. I am using the below code to extract values from an html page:
$content = file_get_contents($_POST['url']);
$resultsArray = array();
$sqlresult = array();
$priceElement = explode( '<div>value I want to extract</div>' , $content );
Now when I use this to get certain elements I only get back
Finance: {{value * value2}}
I want to get the actual value that would be displayed on the screen e.g
Finance: 7.96
The other php methods I have tried are:
curl
file_get_html(using simple_html_dom library)
None of these work either :( Any ideas what I can do?
You just set the <div>value I want to extract</div> as a delimiter, which means PHP looks for it to separate your string to array whenever this occurs.
In the following code we use , character as a delimiter:
<?php
$string = "apple,banana,lemon";
$array = explode(',', $string);
echo $array[1];
?>
The output should be this:
banana
In your example you set the value you want to extract as a delimiter. That's why this happens to you. You'll need to set a delimiter between your string you want to obtain and other string you won't need at the moment.
For example:
<?php
$string = "iDontNeedThis-dontExtractNow-value I want to extract-dontNeedEither";
$priceElement = explode('-', $string);
echo "<div>".$priceElement[2]."</div>";
?>
The code should output this to your HTML page:
<div>value I want to extract</div>
And it will appear on your page like this:
value I want to extract
If you don't need to save the whole array in a variable, you can save the one index of it to variable instead:
$priceElement = explode('-', $string)[2];
echo $priceElement;
This will save only value I want to extract so you won't have to deal with arrays later on.
I want to replace my query result according to the $_GET value like
If I have URL like
URL/?userid=3255
then the output of the userid from the database should replace with $_GET value when printing the database data
PS: I don't want to update the userid in database i just want to replace userid on the front end when printing the data from database
database table:
userid | name
-----------|
userid=4332|ron
Code:
<?php str_replace("userid=","userid=echo $_GET['userid'],"$row['userid']);?>
$row['userid'] is the data that i fetch from the database
Try with this one:
<?php str_replace("userid=","userid=".$_GET['userid'], $row['userid']);?>
but if user changes $_GET['userid'] param printed result will also change according to the new userid param.
You can use parse_url on the url that return an associative array. Then use parse_str that parse the string into variables. Make any changes you need. Then reassemble the address with the changes using http_build_query.
$url = 'http://www.example.com/?userid=3255';
$parsed_url = parse_url($url);
parse_str($parsed_url['query'], $parsed_str);
if(isset($parsed_str['userid']))
{
// make any changes you want
$parsed_str['userid'] = "new id";
// reassemble the address with the changes
$link = "http://$_SERVER[HTTP_HOST]/?";
$http_builded = $link . http_build_query($parsed_str);
}
I hope this can help you.
Hi I am trying to insert my article title in database in the following format this-is-a-new-title for the input This is a new Title. For this I have written :
$title = $this->input->post('topic_title');
$topic_slug_title = url_title($title,'-',TRUE);
But the echo $topic_slug_title shows titles like this_is_a_new_title. Why the underscores are added wherein I have given hyphens ?
Ok I found the solution. Just leave the second parameter as default,add the third parameter. That is:
$title = $this->input->post('topic_title');
$topic_slug_title = url_title($title,TRUE,TRUE);
don't use the third parameter, use it like this
$title = $this->input->post('topic_title');
$topic_slug_title = strtolower(url_title($title));
don't use second and third parameter, write like this:
**$title = $this->input->post('topic_title');
$topic_slug_title = url_title($title);**